Next page Previous page Start of chapter End of chapter

XSLT processors

An XSLT processor is a software that inputs an XML document and a corresponding XSLT stylesheet and outputs the result document by applying the stylesheet to the XML document. An XSLT processor can be built into a web browser, like Mozilla TransforMiiX. Or it can be a standalone program like Michael Kay's Saxon or the xsltproc command line tool from the XSLT library developed for the Gnome project (but usable outside of the Gnome platform).

An XSLT stylesheet is associated to an XML document using the processing instruction with target xml-stylesheet. Its pseudo-attribute type should be the MIME type application/xml, while the pseudo-attribute href should contain the URL of the XSLT stylesheet. For instance, we can associate the stylesheet contained in the file dblp.xsl to our bibliography XML document by adding the following instruction to the XML document:

<?xml-stylesheet type="application/xml" href="dblp.xsl"?>

Both Saxon and xsltproc are command line tools. With Saxon, we can apply dblp.xsl to dblp.xml with the following syntax:

java net.sf.saxon.Transform dblp.xml dblp.xsl

If the XML document contains the stylesheet processing instruction, you can use this syntax:

java net.sf.saxon.Transform -a dblp.xml

Moreover, use option -snone to preserve the whitespace text nodes in the XML document and option -o file to send output to the named file.

The syntax with xsltproc is:

xsltproc dblp.xsl dblp.xml

Use option -o file to send output to the named file.

You may also transform a document with XSLT using BaseX function xslt:transform as in the following example:

let $doc := doc('banking.xml')
let $style := doc('banking.xslt')
return xslt:transform($doc, $style)
Next page Previous page Start of chapter End of chapter
Caffè XML - Massimo Franceschet