• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 807
  • Last Modified:

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

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")
req.open "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" />
  • 4
  • 3
1 Solution
Geert BormansCommented:
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="http://www.w3.org/1999/XSL/Transform">
<xsl:parameter name="paramName" />

hope this helps



nazzie303Author Commented:
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:
Geert BormansCommented:
you did not post the Error message, unless it really only is "??F"

make sure the parameter is defined at the highest level
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

nazzie303Author Commented:
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
Geert BormansCommented:
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


nazzie303Author Commented:
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 ?
Geert BormansCommented:
I think it should work using msxml3
why don't you add .3.0 to make sure it picks up the right parser?



Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now