Pass Query String Value to XSL for filtering

C

Corey

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

Martin Honnen

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: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)
 
C

Corey

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
 
M

Martin Honnen

Corey said:
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.
 
C

Corey

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top