By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,918 Members | 1,852 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,918 IT Pros & Developers. It's quick & easy.

Pass Query String Value to XSL for filtering

P: n/a
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>

Jul 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a


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/
Jul 20 '05 #2

P: n/a
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

Jul 20 '05 #3

P: n/a


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/
Jul 20 '05 #4

P: n/a
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

Jul 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.