Reputation: 406
Is there anyway in which I can get the value of a querystring variable and work with it with xsl. I tried with <xsl:param name="qsVariableName">
, but had no success, it doesnt break but it gives me an empty value when I try to input it like this.
www.example.com?qsVariableName=true
<xsl:param name="qsVariableName" />
<xsl:value-of select="$qsVariableName"></xsl:value-of>
Upvotes: 2
Views: 2538
Reputation: 66714
Querystring parameters from either the source XML file or the XSLT are not automatically mapped to set <xsl:param>
in your stylesheet.
The <xsl:param>
need to be explicitly set when the transform is invoked. Depending upon the environment and how your are invoking it there is different syntax for setting the parameters.
In Java, you would set the parameter with something like this:
javax.xml.transform.Transformer trans =
transFact.newTransformer(xsltSource);
trans.setParameter("qsVariableName", "true");
In XSLT 2.0 you could use the document-uri()
function to obtain the URL of the source XML file and then parse that value to obtain a sequence of the querystring parameter(s) and value(s).
tokenize(substring-after(document-uri(/), '?'), '&')
For instance, with the code above if you were transforming an XML file with the url: http://example.com/file.xml?qsVariableName=true
it would return "qsVariableName=true".
Upvotes: 1