RE: [xsl] accessing URL parameters from XSL

Subject: RE: [xsl] accessing URL parameters from XSL
From: John Pallister <jpallister@xxxxxxxxxxxx>
Date: Mon, 4 Nov 2002 08:38:26 -0500
If you want the parameter value from a URL and you are not using ASP,
client-side applications for example, then you could do
something like the following example.

(using E:\xslt\post\theData.xml?myparam=test1 as an example URL...)

Sample XSL: (doGraph.xsl)

<?xml version="1.0"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:msxsl="urn:schemas-microsoft-com:xslt"
xmlns:url="uri:find-url.org">

<xsl:param name="theParam" />
<xsl:variable name="xmlpath" select="url:findURL(.)" />

<msxsl:script language="JScript" implements-prefix="url">
<![CDATA[ 
     function findURL(nodelist) {      
       return nodelist.nextNode().url;      
     }     
]]>
</msxsl:script>

<xsl:template match="/">
<html>
<head>
</head>

 <body>
  <table>
   <tr><td>The URL is: <xsl:value-of select="$xmlpath" /></td></tr>
  </table>

   <!-- Draw a chart based on selection... -->
   <xsl:call-template name="bar-chart">
    <xsl:with-param name="theParam"
select="substring-after($xmlpath,'myparam=')" />
   </xsl:call-template>

  </body>
 </html>
</xsl:template>

<xsl:template name="bar-chart">
 <xsl:param name="theParam" />
  <table>
   <tr><td>The value is: <xsl:value-of select="$theParam" /></td></tr>
  </table>
  <!-- other code not listed for brevity... -->
</xsl:template>

</xsl:stylesheet>


Sample XML: (theData.xml)

<?xml version="1.0"?>
<?xml-stylesheet type="text/xsl" href="doGraph.xsl" ?>
<data>
<test id="test1" score="10"/>
<test id="test3" score="12"/>
<test id="test1" score="10"/>
<test id="test2" score="16"/>
<test id="test4" score="12"/>
</data>


Then when the following is passed to the browser:

E:\xslt\post\theData.xml?myparam=test1

The following result is displayed:

The URL is: file:///E:/xslt/post/theData.xml?myparam=test1

The value is: test1	


John Pallister
jpallister@xxxxxxxxxxxx




-----Original Message-----
From: Viktor [mailto:viktoras@xxxxxx]
Sent: Monday, November 04, 2002 7:36 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: [xsl] accessing URL parameters from XSL


Hello all,

I'm having problem with accessing URL parameters from XSL. How can I solve
this problem?
I'm using server-side Microsoft MSXML parser.

Viktor.



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread