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

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!!!!



0
dressman
Asked:
dressman
1 Solution
 
Geert BormansCommented:
Hi dressman,

I think your code is correct,
I have a syntactically, slightly different codebase (writes to output.xml)
see below

but I think the issue is in the XSLT

    <xsl:template match="/">
    <xsl:param name="pageID"/>

The parameter "pageID" requires to be GLOBAL (you have one local to the template match = "/")
If you just swap the two lines, at least the XSLT is OK,
and it might work

    <xsl:output method="html" indent="yes" />
    <xsl:param name="pageID"/>
    <xsl:template match="/">

FYI, my code

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("output.xml", Nothing)

'Transform the file.
xslt.Transform(New XPathDocument(Server.MapPath("_Data/Content.xml")), argList, writer, Nothing)

Cheers!
0
 
dressmanAuthor Commented:
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")
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

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