<p>When using a browser to transform XML (Google Chrome or IE7) is it possible to pass a parameter to the XSLT stylesheet through the URL?</p>

<p>example:</p>

<p><strong>data.xml</strong></p>

<pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;?xml-stylesheet type="text/xsl" href="sample.xsl"?&gt;
&lt;root&gt;
    &lt;document type="resume"&gt;
        &lt;author&gt;John Doe&lt;/author&gt;
    &lt;/document&gt;
    &lt;document type="novella"&gt;
        &lt;author&gt;Jane Doe&lt;/author&gt;
    &lt;/document&gt;
&lt;/root&gt;
</code></pre>

<p><strong>sample.xsl</strong></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"
    xmlns:fo="http://www.w3.org/1999/XSL/Format"&gt;

    &lt;xsl:output method="html" /&gt;
    &lt;xsl:template match="/"&gt;
    &lt;xsl:param name="doctype" /&gt;
    &lt;html&gt;
        &lt;head&gt;
            &lt;title&gt;List of &lt;xsl:value-of select="$doctype" /&gt;&lt;/title&gt;
        &lt;/head&gt;
        &lt;body&gt;
            &lt;xsl:for-each select="//document[@type = $doctype]"&gt;
                &lt;p&gt;&lt;xsl:value-of select="author" /&gt;&lt;/p&gt;
            &lt;/xsl:for-each&gt;
        &lt;/body&gt;
    &lt;/html&gt;
&lt;/&lt;xsl:stylesheet&gt;
</code></pre>

[{'answer_id': 66017, 'author': 'Peter Boughton', 'author_id': 9360, 'author_profile': 'https://Stackoverflow.com/users/9360', 'pm_score': 3, 'selected': True, 'text': '<p>You can generate the XSLT server-side, even if the transformation is client-side.</p>\n\n<p>This allows you to use a dynamic script to handle the parameter.</p>\n\n<p>For example, you might specify:</p>\n\n<pre><code>&lt;?xml-stylesheet type="text/xsl"href="/myscript.cfm/sample.xsl?paramter=something" ?&gt;\n</code></pre>\n\n<p>And then in myscript.cfm you would output the XSL file, but with dynamic script handling the query string parameter (this would vary depending on which scripting language you use).</p>\n'}, {'answer_id': 78033, 'author': 'leekelleher', 'author_id': 12787, 'author_profile': 'https://Stackoverflow.com/users/12787', 'pm_score': 3, 'selected': False, 'text': "<p>Unfortunately, no - you can't pass through parameters to the XSLT on the client-side only.\nThe web-browser takes the processing instructions from the XML; and directly transforms it with the XSLT.</p>\n\n<hr>\n\n<p>It is possible to pass values via the querystring URL and then read them dynamically using JavaScript. However these wouldn't be available to use in the XSLT (XPath expressions) - as the browser has already transformed the XML/XSLT.  They could only be used in the rendered HTML output.</p>\n"}, {'answer_id': 635032, 'author': 'Tawani', 'author_id': 61525, 'author_profile': 'https://Stackoverflow.com/users/61525', 'pm_score': 3, 'selected': False, 'text': '<p>Just add the parameter as an attribute to the XML source file and use it as an attibute with the stylesheet.</p>\n\n<pre class="lang-js prettyprint-override"><code>xmlDoc.documentElement.setAttribute("myparam",getParameter("myparam"))\n</code></pre>\n\n<p>And the JavaScript function is as follows:</p>\n\n<pre class="lang-js prettyprint-override"><code>//Get querystring request paramter in javascript\nfunction getParameter (parameterName ) {\n\n   var queryString = window.top.location.search.substring(1);\n\n   // Add "=" to the parameter name (i.e. parameterName=value)\n   var parameterName = parameterName + "=";\n   if ( queryString.length &gt; 0 ) {\n      // Find the beginning of the string\n      begin = queryString.indexOf ( parameterName );\n      // If the parameter name is not found, skip it, otherwise return the value\n      if ( begin != -1 ) {\n         // Add the length (integer) to the beginning\n         begin += parameterName.length;\n         // Multiple parameters are separated by the "&amp;" sign\n         end = queryString.indexOf ( "&amp;" , begin );\n      if ( end == -1 ) {\n         end = queryString.length\n      }\n      // Return the string\n      return unescape ( queryString.substring ( begin, end ) );\n   }\n   // Return "null" if no parameter has been found\n   return "null";\n   }\n}\n</code></pre>\n'}]
['https://Stackoverflow.com/questions/65926', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/9547/']