Link to home
Start Free TrialLog in
Avatar of dressman
dressman

asked on

Use XsltArgumentList to pass param to XSLT to filter XML file

What I am trying to do is display only a certain Page information but when i use:
            Xml1.DocumentSource = Server.MapPath("_Data/Content.xml")
            Xml1.TransformSource = Server.MapPath("_Data/Content.xslt")
it will display all of the information. Not just SandVolleyball or Childcare.  I would like to pass a parameter to the XSLT and display only that page information.

XML:

<root>
<page>
            <id>SandVolleyball</id>
            <description>5 Professional Sand Volleyball Courts!</description>
            <misc></misc>
                  <group>
                        <title>Sand Volleyball Rates</title>
                        <misc></misc>
                        <item>
                              <title>1 Hour Rental/Court</title>
                              <fee>$6.00</fee>
                        </item>
                  </group>
            
      </page>
      <page>
            <id>ChildCare</id>
            <description>Our experienced childcare attendants are eager to work with your children</description>
            <misc></misc>
            
                  <group>
                        <title>Child Care Rates</title>
                        <misc></misc>
                        <item>
                              <title>20 Punch Pass</title>
                              <fee>$26.00</fee>
                        </item>
                  </group>
            
      </page>
</root>
-----------------------------------------
XSLT:

<xsl:stylesheet version="1.1" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" indent="yes" />
<xsl:template match="/">
<xsl:param name="pageID"/>
<xsl:for-each select="/root/page">
      <xsl:value-of select="description"/><br />
            <xsl:for-each select="group[id='$pageID']">
                  <xsl:value-of select="title"/><br />
                  <table>
                        <xsl:for-each select="item">
                        <tr>
                              <td><xsl:value-of select="title"/></td>
                              <td><xsl:value-of select="fee"/></td>
                              </tr>
                        </xsl:for-each>
                  </table>
                  <xsl:value-of select="misc"/><br />
            </xsl:for-each>
      <xsl:value-of select="misc"/><br />      
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>

This is a guess:
            Dim doc As XPathDocument = New XPathDocument(Server.MapPath("_Data/Content.xml"))
            Dim xsldoc As New XslTransform
            xsldoc.Load(Server.MapPath("_Data/Content.xslt"))
            Dim args As New XsltArgumentList
            args.AddParam("pageID", "", Request.QueryString.Item("Page").ToString)
            xsldoc.Transform(doc, args, Me.Xml1.Document, Nothing)


Please HELP!!!!



ASKER CERTIFIED SOLUTION
Avatar of Gertone (Geert Bormans)
Gertone (Geert Bormans)
Flag of Belgium image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dressman
dressman

ASKER

okay, i now get it to filter.  how can i get it to display in the XML ASP.NET control??

            'LoadXML(Request.QueryString.Item("Page").ToString)
            Dim xslt As New XslTransform
            xslt.Load(Server.MapPath("_Data/Content.xslt"))

            'Create the XsltArgumentList.
            Dim argList As New XsltArgumentList

            argList.AddParam("pageID", "", Request.QueryString.Item("Page").ToString())

            'Create the XmlTextWriter.
            'Dim writer As New XmlTextWriter(Server.MapPath("_Data/output.xml"), Nothing)

            'Transform the file.
            Me.Xml1.TransformArgumentList = argList
            Me.Xml1.DocumentSource = Server.MapPath("_Data/Content.xml")
            Me.Xml1.TransformSource = Server.MapPath("_Data/Content.xslt")