Pass Query String Value to XSL for filtering

Discussion in 'XML' started by Corey, Feb 15, 2005.

  1. Corey

    Corey Guest

    All,

    I am relatively new to XML and I have what may sound like a dumb
    question. I want to pass a query string variable to my xml document
    and filter the output based on that variable. For example, if I type
    in www.mysite.com?geid=0000123468 I want to display only
    AccessReview/Report where GEID='0000123468'. I appreciate any help you
    can provide.

    Corey

    Here is the code for my request.

    ---------------------------------------------------
    XML file
    ---------------------------------------------------
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <?xml-stylesheet type="text/xsl" href="AccessReview.xsl"?>
    <Records>
    <AccessReview>
    <Report>Corey's Report</Report>
    <GEID>0003620195</GEID>
    </AccessReview>
    <AccessReview>
    <Report>Kim's Report #1</Report>
    <GEID>0000123468</GEID>
    </AccessReview>
    <AccessReview>
    <Report>Kim's Report #2</Report>
    <GEID>0000123468</GEID>
    </AccessReview>
    <AccessReview>
    <Report>Kim's Report #3</Report>
    <GEID>0000123468</GEID>
    </AccessReview>
    <AccessReview>
    <Report>Ron's Report #1</Report>
    <GEID>0000204138</GEID>
    </AccessReview>
    <AccessReview>
    <Report>Ron's Report #2</Report>
    <GEID>0000204138</GEID>
    </AccessReview>
    <AccessReview>
    <Report>Ron's Report #3</Report>
    <GEID>0000204138</GEID>
    </AccessReview>
    <AccessReview>
    <Report>Ron's Report #4</Report>
    <GEID>0000204138</GEID>
    </AccessReview>
    </Records>

    ---------------------------------------------------
    XSL file
    ---------------------------------------------------
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

    <xsl:template match="/">
    <html>
    <head><title>Access Review</title>
    </head>

    <body>
    <pre>
    <xsl:for-each select="Records/AccessReview[GEID=variableName]">
    <xsl:value-of select="Report"/>
    </xsl:for-each>
    </pre>
    </body>
    </html>

    </xsl:template>
    </xsl:stylesheet>
     
    Corey, Feb 15, 2005
    #1
    1. Advertising

  2. Corey wrote:


    > I am relatively new to XML and I have what may sound like a dumb
    > question. I want to pass a query string variable to my xml document
    > and filter the output based on that variable. For example, if I type
    > in www.mysite.com?geid=0000123468 I want to display only
    > AccessReview/Report where GEID='0000123468'.


    Write a server-side script in the language of your choice (or the one
    your server supports) to read out the query string first, then create an
    XSLT processor, pass in the query string value as a parameter to the
    stylesheet, run the transformation and send the result back to the browser.




    > <?xml version="1.0" encoding="ISO-8859-1"?>
    > <xsl:stylesheet version="1.0"
    > xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


    A global stylesheet parameter is defined as
    <xsl:param name="GEID" />
    and then used as

    > <xsl:for-each select="Records/AccessReview[GEID=variableName]">


    <xsl:for-each select="Records/AccessReview[GEID=$GEID]">

    How you pass parameters to a stylesheet depends on the processor used,
    usually there is an API alike
    processor.setParam(name, value)
    respectively
    processor.setParam(name, namespace, value)


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Feb 15, 2005
    #2
    1. Advertising

  3. Corey

    Corey Guest

    Thanks Martin. Is there any way to do it without using a server side
    script? I'm a .NET guy but this project requires the use of a Unix
    server which I know nothing about, including PHP and perl. Is there
    any other way to do this? I appreciate your help.

    Corey
     
    Corey, Feb 15, 2005
    #3
  4. Corey wrote:

    > Is there any way to do it without using a server side
    > script? I'm a .NET guy but this project requires the use of a Unix
    > server which I know nothing about, including PHP and perl. Is there
    > any other way to do this?


    If you want to ensure visitors see the result of the XSLT transformation
    then you have to do the transformation on the server, whether you want
    to read the query string or not, browser support for XSLT
    transformations is certainly not something to rely on on the web in general.
    If you are sure you have only IE 6/Win clients (or IE 5/5.5 Win clients
    with an updated version of MSXML 3 installed) or Mozilla 1.2 and later
    clients with scripting enabled then of course you could start with an
    HTML page with Javascript reading the query string and then doing the
    transformation client-side triggered by script.
    Sarissa is a library which can help with that:
    <http://sarissa.sourceforge.net/doc/>
    But as said, on the web in general relying on client-side XSLT is not a
    solution, you need to provide alternatives then anyway.


    --

    Martin Honnen
    http://JavaScript.FAQTs.com/
     
    Martin Honnen, Feb 16, 2005
    #4
  5. Corey

    Corey Guest

    I completely agree with your thoughts. This is just a band-aid
    approach until an enterprise application can be built. Thanks for your
    help.

    Corey
     
    Corey, Feb 16, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    1
    Views:
    3,637
    A. Bolmarcich
    May 27, 2005
  2. Machelle Chandler

    Using query string to pass a value to a stored procedure parameter

    Machelle Chandler, Oct 21, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    178
    Machelle Chandler
    Oct 21, 2003
  3. sathya

    how to pass query string value(help me)

    sathya, Oct 29, 2007, in forum: ASP .Net Web Services
    Replies:
    1
    Views:
    176
    Cowboy \(Gregory A. Beamer\)
    Oct 29, 2007
  4. cooldv
    Replies:
    1
    Views:
    149
    Aaron Bertrand [MVP]
    Sep 13, 2003
  5. nick
    Replies:
    1
    Views:
    477
    David Mark
    Feb 13, 2011
Loading...

Share This Page