1

I have written an xslt document to transform an xml file in html. Now I would like to pass a parameter from the url to a xslt variable, so that I can display a specific xml entry from the xml document in Firefox 9.0.1. To do so, I use a javascript function that returns me the value of the url parameter. Now my question : Is it possible in Firefox to pass the return value of the javascript function to a xslt variable?

Thanks a lot for an answer!

4
  • 1
    The xslt runs before JavaScript does. Not going to happen that way. Commented Jan 7, 2012 at 14:39
  • 2
    possible duplicate of querystring using xslt Commented Jan 7, 2012 at 14:40
  • 1
    How are you executing the transform? Are you loading an XML file with a processing instruction for the XSLT, or are you loading an HTML file with JavaScript to transform an XML file? Commented Jan 7, 2012 at 17:21
  • I'm using an xml file with <?xml-stylesheet type="text/xsl" href="./test.xsl"?> Commented Jan 9, 2012 at 17:36

1 Answer 1

0

Something like the following might work.

XSL:

<xsl:value-of select='*[name()="__TAG_NAME__"]' />

JS (jQuery assumed; also, W3C-code only, not IE)

var tagName = location.href.match(/tagName=([^&]+)/),
    output;
if (tagName) {
    $.ajax({url: 'path/to/xsl.xsl', dataType: 'text'}).done(function(xsl) {
        var xsltProcessor = new XSLTProcessor();
        xsltProcessor.importStylesheet(xsl.replace('__TAG_NAME__', tagName[1]);
        var doc = xsltProcessor.transformToFragment(xml,document);
        output = doc.innerHTML;
    });
}
Sign up to request clarification or add additional context in comments.

Comments

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.