XML information pipe
Ihre Spezialisten für XML
Page 1
XSLT introduction
With XSL you can freely modify any source text. XSLT stylesheet 1 and XSLT stylesheet 2 produce different output from the same source file.
XSLT 1.0 tutorialPage 2
Root element
Every XSL stylesheet must start with xsl:stylesheet element. The atribute version='1.0' specifies version of XSL(T) specification. This example shows the simplest possible stylesheet. As it does not contain any information, default processing is used.
XSLT 1.0 tutorialPage 3
Intructions inside xsl:template
An XSL processors parses an XML source and tries to find a matching template rule. If it does, instructions inside matching template are evaluated.
XSLT 1.0 tutorialPage 4
xsl:value-of | xsl:apply-templates
Contents of the original elements can be recovered from the original sources in two basic ways. XSLT stylesheet 1 uses xsl:value-of construct. In this case the contents of the element is used without any further processing. The instruction xsl:apply-templates in XSLT stylesheet 2 is different. The parser further processes selected elements, for which a template is defined.
XSLT 1.0 tutorialPage 5
Page 5 ist identisch zu Page 3An XSL processors parses an XML source and tries to find a matching template rule. If it does, instructions inside matching template are evaluated.
XSLT 1.0 tutorialPage 6
XPath location steps
Parts of XML document to which template should be applied are determined by location paths. The required syntax is specified in the XPath specification. Simple cases looks very similar to filesystem addressing. ( XSLT stylesheet 1 )
XSLT 1.0 tutorialPage 7
implicit template use
Processing always starts with the template match="/" . This matches the root node (the node its only element child is the document element, in our case "source"). Many stylesheets do not contain this element explicitly. When this template is not explicitly given, the implicit template is used (it contains as the sole instruction). This instruction means: process all children of the current node, including text nodes. Compare XSLT stylesheet 1 and XSLT stylesheet 2 . When a template for the node exists, there is no default processing invoked ( XSLT stylesheet 3 ). If you want to include descendants of the node, you have to explicitly request their templates ( XSLT stylesheet 4 ).
XSLT 1.0 tutorialPage 8
" | " or Wildcard
A template can match from a selection of location paths, individual paths being separated with "|" ( XSLT stylesheet 1 ). Wildcard "*" selects all possibilities. Compare XSLT stylesheet 1 with XSLT stylesheet 2 .
XSLT 1.0 tutorialPage 9
Location step with "//"
"//" is very common in location paths. When it is used at the beginning of a location path, it means: select all nodes in the document of the specified type ( XSLT stylesheet 1 ). In the middle of a location path it means: select all nodes which appear in the node selected with the first part of the location path ( XSLT stylesheet 2 ).