XML technologies / XSLT / Introduction to XSLT 2.0 / Getting started with XSLT and XPath / A comparison: expression vs. instruction / Variant 1: the XSLT-oriented approach
(Excerpt from "XSLT 2.0 & XPath 2.0" by Frank Bongers, Chapter 1.)
An obvious way to put the output into the required order would be the following:
<!-- Template-Regel für <anschrift>: -->
<xsl:template match="anschrift">
<!-- in Reihenfolge der Ausgabe: -->
<xsl:value-of select="strasse"/>
<xsl:value-of select="nr"/>,
<xsl:value-of select="plz"/>
<xsl:value-of select="ort"/>
</xsl:template>
Code example: kap01/1.16.1/adressen.xsl.
The text nodes are simply generated in the required order, each by a separate instruction.
This solution has the advantage of also working smoothly with older processors in an XSLT 1.0 context. The overlap between the two language versions is large enough to write an XSLT 2.0 stylesheet that is also valid XSLT 1.0/XPath 1.0 and is accepted by a newer processor as XSLT 2.0/XPath 2.0.
Whether processing with XSLT 1.0 or 2.0, however, the approach introduces a small problem with the desired output. Fortunately, the solution presented next also works in both cases.
Copyright © Galileo Press, Bonn 2008
You may print the online version for your private use.
Otherwise, this chapter from "XSLT 2.0 & XPath 2.0 ― Das umfassende Handbuch" is subject to the same terms as the printed edition: the work and all its parts are protected by copyright. All rights are reserved, including reproduction, translation, microfilming, and storage and processing in electronic systems.
Galileo Press, Rheinwerkallee 4, 53227 Bonn