There are two XSLT standards that are not totally compatible and they rely on XPath to define selections.

XSLT and XPath
XSLT 1.0 and XPath 1.0: 16 November 1999, widely implemented and used
XSLT 2.0 and XPath 2.0: 23 January 2007, main implementation is by Saxon
XSLT 2.0 is incompatible with XSLT 1.0
  • Most features work the same
  • XSLT 1.0 is tolerant in terms of type conversions, XSLT 2.0 is not
  • Significantly different behaviour occurs with some widely-used functions
  • Changes in behaviour and new features have been added to aid compatibility with XQuery
  • Claim is that XSLT 2.0 provides better support for grouping and manipulating strings. It does provide simpler instructions for these tasks
  • XSLT 2.0 processors are expected to have an option to run in XSLT 1.0 compatibility mode and Saxon does

This is the main function of XSLT:

XML Document Parsing Source Tree XSLT Transformation XPath Result Tree Serialisation XML Document

It transforms an XML application into another XML application which can be SVG.

The main functions are:

Traverse Input Tree
Set of templates that match specific nodes and define action to be taken
<xsl:apply-templates select="nodeset_reference"/>
Defines a set of nodes to be processed
Default template that traverses the input tree when no other matching templates provided
Create Output Tree
Set of template instructions:
<xsl:text>some text</xsl:text>
Outputs the text string to the output tree at the current position
<xsl:value-of select="node_reference"/>
Outputs node content from input tree to output tree
<xsl:copy>
Copies node of input tree to output tree (shallow copy, does not copy attributes or children)
<xsl:copy-of select="nodeset_reference"/>
Copies subtree from input tree to output tree
Literal Result Element
XML element within template body that is not an XSLT instruction. Treated as data and copied to output tree. Can handle multiple namespaces

The strength of XSLT is that you need only transform the bits that need changing and you can leave the rest as is.

Here is a standard template that copies everything:

<xsl:template match="attribute::*|child::*" >
<xsl:copy>
<xsl:apply-templates select="attribute::*" />
<xsl:apply-templates />
</xsl:copy>
</xsl:template>

This copies everything applying any changes by defining specific templates for the things to be transformed.

So if you only want to transform, say, path elements in SVG, the rest of the structure will stay the same.

Could be more precisely written and using the abbreviations as:

<xsl:template match="@*|*|text()" >
<xsl:copy>
<xsl:apply-templates select="@*|*|text()" />
</xsl:copy>
</xsl:template>

This template tends to be a bit of the standard infrastructure as it is in path_ology.

Templates with a match pattern of text() match text nodes, * means any node, @* means any attribute.

xsl:template

This is the main transformer in XSLT.

<xsl:template match="" name=""  priority="" mode=""/>
  • match attribute is a pattern to define which nodes the template can be applied to by xsl:apply-templates
  • If the pattern contains several location steps (such as first/second/third), the process is to check if the node to be processed is a third element and if its parent is a second element and so on

The main vehicle for transforming simple XSLT is Saxon 6.5.5:

You need to write something like:

java -jar saxon.jar  -o exout.svg ex.xml ex.xsl 
or
java -jar saxon9.jar -t ex.xml  ex.xsl >exout.xml

This transforms ex.xml by ex.xsl to produce exout.svg. First is XSLT 1.0 and second XSLT 2.0.