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



dressmanAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Geert BormansInformation ArchitectCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.