XML technologies / XSLT / Introduction to XSLT 2.0 / XSLT and XPath – getting started / Instructions in the template body

(Excerpt from “XSLT 2.0 & XPath 2.0” by Frank Bongers, chapter 1.)

Inside the template body are further elements identified by the prefix xsl. They are commands to the XSLT processor: they are instructions causing particular actions. They may, but need not, be surrounded by Literal Result Elements and are executed where they appear:

 

Code example: kap01/1.08/beispiel.xsl.

...
  <body>
    <h1 align="center">Die dritte XSLT-Transformation</h1>
    <p align="center"><xsl:value-of select="wurzelelement"/></p>
  </body>
...

The result document contains no trace of the instruction itself; only its result takes its place:

Code example: kap01/1.08/beispiel.html.

...
  <body>
    <h1 align="center">Die dritte XSLT-Transformation</h1>
    <p align="center">Das ist ein Testinhalt aus 'dummy.xml'.</p>
  </body>
...

Example: xsl:value-of

Instruction xsl:value-of produces text appearing in the result document.

The text comes from the XPath expression in the required select attribute. Its result is always converted to a character string, string, hence the term string value of the expression.

Here the XPath expression addresses a source element by name, telling the processor to extract its string value (value) from element <wurzelelement>:

<xsl:value-of select="wurzelelement"/>

Imagine the processor reaching into the source to retrieve information at the specified position, located by an XPath expression in attribute select of xsl:value-of.

The author must know the source structure: element <wurzelelement> must exist at a known position. This is less trivial than it may seem.

XPath expression versus XPath pattern

An XPath expression or expression encompasses anything expressible in XPath. Expression is the general term; a pattern is a special subset.

An expression may be a path identifying part of the source, or contain function calls such as fn:funktionsname() returning a value to the calling instruction. It can also contain control structures, such as for loops and conditions using if ... then ... else ....

Later chapters cover XPath expressions in detail. For now we examine their simpler subset, path expressions. Before doing so, another look at XML documents from a different angle will help.

   

back to top