XML technologies / XSLT / Introduction to XSLT 2.0 / Getting started with XSLT and XPath / Stylesheets with multiple templates / Breakdown: the limits of the string value
(Excerpt from "XSLT 2.0 & XPath 2.0" by Frank Bongers, Chapter 1.)
First, following the approach that worked in the preceding example, let us try to read the addresses in the following form:
<!-- der Dokumentknoten bildet den Kontext: -->
<xsl:template match="/">
...
<h1>Adressenliste</h1>
<!-- dies funktioniert nicht wie gewünscht: -->
<p><xsl:value-of select="adressen/adresse"/></p>
...
</xsl:template>
Code example: kap01/1.15.2/adressen.xsl (excerpt).
A problem arises immediately: the result does not have the desired form. All elements <adresse> are indeed selected, but they all appear together in a single <p> container. (Warning: In XSLT 1.0, only the string value of the first <adresse> element would be obtained. There is a difference here in the effect of xsl:value-of.)
Figure: all addresses are output at once.
In fact, a sequence of the individual addresses’ string values is created. Unfortunately, this is not immediately useful (the behavior of xsl:value-of with sequences is discussed on the following pages). The individual elements’ string values merge into a single text node in the result document. Each address should instead be processed separately.
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