Note that there are some explanatory texts on larger screens.

plurals
  1. POhow to supply stylesheet variable value from html or javascript
    primarykey
    data
    text
    <p>My issue is regarding rendering on client that uses xsl. This already works in IE but I want to make it work on firefox</p> <p>First, the stylesheet (variablexsl.xsl) The only thing special here is the existence of</p> <p><code>&lt;xsl:variable name="module" select="string('RES')"/&gt;</code></p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8" ?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:template match="/"&gt; &lt;xsl:variable name="module" select="string('RES')"/&gt; &lt;table cellpadding="0" cellspacing="0" border="0" ID="randomID"&gt; &lt;tr&gt; &lt;xsl:choose&gt; &lt;xsl:when test="$module = 'EDU'"&gt; &lt;td&gt;EDU was supplied..&lt;/td&gt; &lt;/xsl:when&gt; &lt;/xsl:choose&gt; &lt;/tr&gt; &lt;tr&gt; &lt;xsl:choose&gt; &lt;xsl:when test="$module = 'RES'"&gt; &lt;td&gt;RES was supplied..&lt;/td&gt; &lt;/xsl:when&gt; &lt;/xsl:choose&gt; &lt;/tr&gt; &lt;/table&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt; </code></pre> <p>Now, the html file index.html</p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script&gt; function selectmTab(args) { var xml = loadXMLDoc("variabledata.xml"); //ajax call and holds the responseXML. variabledata.xml is empty var xsl = loadXMLDoc("variablexsl.xsl"); //ajax call and holds the responseXML var ss2 = xsl.selectSingleNode('//xsl:variable/@select'); ss2.value = "string('" + args + "')"; document.getElementById("xsltest").innerHTML = xml.transformNode(xsl); } &lt;/script&gt; &lt;/head&gt; &lt;body onload="displayResult()"&gt; &lt;div&gt; &lt;input type="button" value="EDU" onclick="selectmTab('EDU');" /&gt; &lt;input type="button" value="RES" onclick="selectmTab('RES');" /&gt; &lt;/div&gt; &lt;div id="xsltest"&gt;&lt;/div&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>so finally when i click the buttons EDU and RES, the text is getting displayed properly in IE but not in any other browser. I tried to using document.evaluate() but kept getting errors.. and finally turned to SO for help!</p> <p>Thanks!</p> <p><strong>Solution:</strong> Making the following changes to the stylesheet, and then using the xsltprocessor().setParameter worked for me.</p> <p><strong>Changes to the Stylesheet</strong>: (Addition of a new xsl:param right after the stylesheet declaration)</p> <pre><code>&lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:param name="winnersOnly"&gt;RES&lt;/xsl:param&gt; </code></pre> <p>And, then modifying the <code>&lt;xsl:variable&gt;</code> declaration right after <code>&lt;xsl:template match="/"&gt;</code> as follows: </p> <pre><code>&lt;xsl:template match="/"&gt; &lt;xsl:variable name="module" select="$winnersOnly"/&gt; </code></pre> <p><strong>Client Code for firefox</strong></p> <p>//<code>function loadXMLDoc()</code> makes an ajax request using the <code>XMLHttpRequest</code> object, and returns the <code>responseXML</code> to the caller.</p> <pre><code>var processor = new XSLTProcessor(); xslholder = loadXMLDoc("styles.xsl"); processor.importStylesheet(xslholder); processor.setParameter(null, "winnersOnly", "EDU"); //setting the value here xmlholder = loadXMLDoc("data.xml"); var ownerDocument = document.implementation.createDocument("", "test", null); var newFragment = processor.transformToFragment(xmlholder, ownerDocument); document.getElementById("fragment").appendChild(newFragment); </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload