Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to pass a parameter to XSLT through a URL when using a browser to transform XML?

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?

example:

data.xml

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

sample.xsl

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
    version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:fo="http://www.w3.org/1999/XSL/Format">

    <xsl:output method="html" />
    <xsl:template match="/">
    <xsl:param name="doctype" />
    <html>
        <head>
            <title>List of <xsl:value-of select="$doctype" /></title>
        </head>
        <body>
            <xsl:for-each select="//document[@type = $doctype]">
                <p><xsl:value-of select="author" /></p>
            </xsl:for-each>
        </body>
    </html>
</<xsl:stylesheet>
like image 846
user9547 Avatar asked Sep 15 '08 19:09

user9547


People also ask

How do I use XSLT to XML in browser?

Use the transformNode() method to apply the XSL style sheet to the xml document. Set the body of the current document (id="example") to contain the styled xml document.

Can Chrome be made to perform an XSL transform on a local file?

The short answer is "No, use one of the diverse set of browsers out there". The reason this doesn't work is due to a security concern that Chrome has addressed in a controversial way, by blocking XML files from accessing local XSLT files in the same directory, while HTML files can access .

How XSLT works with XML?

XSLT is used to transform XML document from one form to another form. XSLT uses Xpath to perform matching of nodes to perform these transformation . The result of applying XSLT to XML document could be an another XML document, HTML, text or any another document from technology perspective.

How do I pass multiple parameters in XSLT?

Answer. In order to pass multiple parameters to XSLT from BP you'll need to pass '=' as a separator.


1 Answers

Unfortunately, no - you can't pass through parameters to the XSLT on the client-side only. The web-browser takes the processing instructions from the XML; and directly transforms it with the XSLT.


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.

like image 52
leekelleher Avatar answered Sep 17 '22 10:09

leekelleher