Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Which browser can show XML data transformed by XSLT?

Tags:

say, if there is a file that's call data.xml, and a file that is format.xsl (or is it format.xml ?), which is to transform the XML data and format it as well using CSS, then which browser can display it? Which file should be opened? (the .xsl or the .xml?)

Actually I saw in another example that the XSLT file's first line is to href="format.xsl", so I thought the XSLT file is already the .xsl ? then how come it is linking to another .xsl file? How many files are there, 2 or 3?

like image 923
nonopolarity Avatar asked Aug 12 '10 10:08

nonopolarity


People also ask

Which browser supports XSLT?

Web browsers: Safari, Chrome, Firefox, Opera and Internet Explorer all support XSLT 1.0 (only). Browsers can perform on-the-fly transformations of XML files and display the transformation output in the browser window.

Does Firefox support XSLT?

Note: Since Firefox 7, both text/xsl and application/xslt+xml are supported MIME types for XSLT media stylesheets. Note that Firefox will override your XSLT stylesheet if your XML is detected as an RSS or Atom feed.

Which is used to transform XML data based on the XSLT script?

XSLT stands for Extensible Stylesheet Language Transformation. 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 .


2 Answers

There are two files, one .xml containing data and one .xsl with the XSLT script for transformation. As of August, 2010, all leading browsers support client side XSLT transformation. Open the .xml file and the associated .xsl file will be used. Usually the script builds an html document which is displayed on the fly. The transformation can also be done by the server with PHP etc.
To associate a XSLT script, the .xml file needs a line like this:

<?xml-stylesheet type="text/xsl" href="script.xsl" ?> 

Edit 18.04.2021: The question is 10 years old now and a lot has happened. It's possible now to have XSLT 3.0 running in the browser using Saxon-JS. There's a Hello World on Github.

like image 122
Andreas Avatar answered Sep 19 '22 05:09

Andreas


Many browsers support the XML-stylesheet processing instruction. If it is included in an XML file and you open this XML with your browser, the browser will load the specified XSLT, run it with the XML file as input and display the XSLT's output instead of the original XML document. The spec can be found here: http://www.w3.org/TR/xml-stylesheet/

Wikipedia's XSLT entry has an example of how to use the processing instruction. Basically you just need to add this line at the top of your XML file (after the <?xml?> prolog), with 'example2.xsl' being a path to your XSLT file:

<?xml-stylesheet href="example2.xsl" type="text/xsl" ?>

Firefox and IE should both support this (and probably many other browsers, but I never tried - this feature is not used that often).

like image 20
Tim Jansen Avatar answered Sep 21 '22 05:09

Tim Jansen