Passing parameters from ASP to XML/XSL and filtering data.

Posted on 2007-08-02
Last Modified: 2008-01-09
I have an ASP Page that displays the files from a directory on unix box. I get the entire list of files in that directoty and displays it on the browser. What I want to achieve is to get an input from user (on ASP page, and it will be a letter A, B, C etc..) and then pass this value to the XSL and then it should only display the files beginning from this letter.I have not worked with passing parameters or filtering data dynamically.

My XML Code
Set req = Server.CreateObject("MSXML2.ServerXMLHTTP")
Set xml = Server.CreateObject("MSXML2.DOMDocument")
Set resDoc = Server.CreateObject("MSXML2.DOMDocument")
Set xslDoc = Server.CreateObject("MSXML2.DOMDocument") "POST", service, false
req.setRequestHeader "Content-Type", "text/xml; charset=utf-8"
req.setRequestHeader "SOAPAction", " "
ret = req.send(doc)
xml.async = False
xml.loadXML req.responseText
resDoc.async = False
resDoc.loadXML dirRet.firstChild.text
xslDoc.async = False

Response.Write resDoc.transformNode(xslDoc)

My XSLT Code: (file2,xsl)
<table border="1" cellpadding="2" cellspacing="0">
      <td class="colheading">File Name</td>
<xsl:for-each select="file[@type = 'f']">
    <xsl:sort select="@name" />
    xsl:apply-templates select="."/>

<xsl:template match="file">
      <td class="reportdetail">
            <xsl:attribute name="href">javascript:void(0);</xsl:attribute>
            <xsl:attribute name="onclick">javascript:showFile('<xsl:value-of select="@path" />'); return false;</xsl:attribute>
            <xsl:value-of select="@name" />
Question by:nazzie303
    LVL 60

    Expert Comment

    by:Geert Bormans
    For passing parameters you need a template processor instead of an ordinairy transform
    Here is an example

    <% @Language = "VBScript" %>
    Dim oXML
    Set oXML = Server.CreateObject("MSXML2.DOMDocument.4.0")
    Dim oXSL
    Set oXSL= Server.CreateObject("Msxml2.FreeThreadedDOMDocument.4.0")
    Dim oTmpl
    Set oTmpl= Server.CreateObject("Msxml2.XSLTemplate.4.0")
    Dim oProc

    oXSL.async = false
    oXSL.load Server.MapPath("listing.xsl")

    oXML.validateOnParse = true
    oXML.load Server.MapPath("listing.xml")

    oTmpl.stylesheet = oXSL

    Set oProc= oTmpl.createProcessor()
    oProc.input = oXML
    oProc.addParameter "paramName","paramValue"
    oProc.output = Response


    I believe you can work your code into this example

    For the parameter to be accessible in the XSL,
    you need to add a global parameter with the same name,
    like this

    <xsl:stylesheet version="1.0" xmlns:xsl="">
    <xsl:parameter name="paramName" />

    hope this helps




    Author Comment

    I used the following in my xml:
    proc.addParameter "fname", "A000263.txt"
    proc.output = Response

    And the following in my XSL:
     (i havent even used the parameter in xsl., just trying to see if it the data displays)
    <xsl:param name="fname"></xsl:param>

    And instead of the data displayed, I get the following Error:
    LVL 60

    Expert Comment

    by:Geert Bormans
    you did not post the Error message, unless it really only is "??F"

    make sure the parameter is defined at the highest level

    Author Comment

    Well my main ASP page has div (or frames) and one of the frames is where the list of files is displayed. If I use the method you provided I get the "??F" displayed. I tried finding if this is a valid error, but I cant seem to put a finger on it. Seems like the XML does not like the way parameters are added.
    And yes, I defined the parmeter at the highest level in the XSL
    LVL 60

    Accepted Solution

    Of course this is very hard to debug from a distance.
    I usually work my way up, first checking if the files are loaded correctly
    (outputting an oXML.xml)

    In my example I used the msxml4 activeX objects,
    I hope you changed that, or have msxml4 installed.
    It usually is not a good idea to mix objects from different parsers

    I would personally install msxml6 and use the version 6 PIDs



    Author Comment

    I guess I am much lower on the ladder for this code. So if I was not using the  msxml4, and using the older one (example:--Set xslDoc = Server.CreateObject("MSXML2.FreeThreadedDOMDocument")---)
    this does not support parameters ?
    LVL 60

    Expert Comment

    by:Geert Bormans
    I think it should work using msxml3
    why don't you add .3.0 to make sure it picks up the right parser?



    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Why You Should Analyze Threat Actor TTPs

    After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

    Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
    Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
    It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now