2

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>
2
  • How exactly is the XSLT being invoked? Is it using Javascript? What does that part of your code look like? Commented Sep 4, 2012 at 17:27
  • I assume that this is a client-side transformation? Commented Sep 5, 2012 at 2:01

1 Answer 1

1

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(/), '?'), '&amp;')

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".

Sign up to request clarification or add additional context in comments.

1 Comment

How about in XSLT 1.0 ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.