Running Transformations

There are several strategies to performing a transformation, depending on your needs. If you want a transformed document for your own use, you could run a program such as Saxon to transform it on your local system. With web documents, the transformation is performed either on the server side or the client side. Some web servers can detect a stylesheet declaration and transform the document as it’s being served out. Another possibility is to send the source document to the client to perform the transformation. Internet Explorer 5.0 was the first browser to implement XSLT,[1] opening the door to this procedure. Which method you choose depends on various factors such as how often the data changes, what kind of load your server can handle, and whether there is some benefit to giving the user your source XML files.

If the transformation will be done by the web server or client, you must include a reference to the stylesheet in the document as a processing instruction, similar to the one used to associate documents with CSS stylesheets. It should look like this:

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

The type attribute is a MIME type.[2] The attribute href points to the location of the stylesheet.

[1] Actually, this isn’t strictly true, as one of my reviewers pointed out. Jeni Tennison writes, “Internet Explorer 5.0 didn’t support XSLT unless you installed MSXML3 in replace mode. Otherwise, it supported WD-xsl (Microsoft’s version),” which is a bastardized ...

Get Learning XML, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.