views:

46

answers:

3

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?

+1  A: 

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).

Tim Jansen
just tried the current Safari and Chrome and they both support it, although Chrome didn't open it if it is a local file.
動靜能量
If the XSL is transforming the XML to XHTML, Chrome should open/transform a local file if the XHTML namespace is added to the XSL. I've had to do the same thing for FireFox in local XML files. See: http://stackoverflow.com/questions/2981524/how-can-i-make-xslt-work-in-chrome
DevNull
+1  A: 

There are two files, one .xml containing data and one .xsl with the XSLT script for transformation. 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" ?>
Andreas
A: 

Firefox and Internet Explorer (definitely version 6 and up, likely earlier versions too) can parse XML/XSL well. You could actually write a client-side parser in Javascript, both those browsers work well with that.

You'll probably want to make sure that you don't use any vendor-specific pieces, tho, which can break compatibility (such as <msxsl:script>). The same might apply to other parsers (for example the node-set() function, which isn't the same between MSXML all parsers).

Within your XSL file, you may include another XSL file. Or more XSL files. That way, you can re-use templates from one XSL file in another.

Rob