XML technologies / XSLT / Introduction to XSLT 2.0 / Getting started with XSLT and XPath / Getting started with XPath: path expressions / Knowing where: finding content
(Excerpt from "XSLT 2.0 & XPath 2.0" by Frank Bongers, Chapter 2.)
Two simple XML documents were created for demonstration. In the first version, an element <hallo> is inside the element <gruss>:
Code example: kap01/1.11.1/gruss.xml.
<?xml version="1.0" encoding="ISO-8859-1"?>
<gruss>
<hallo>Hallo Welt! Dies ist XSLT.</hallo>
</gruss>
In the second version, it is outside and therefore forms the root element:
Code example: kap01/1.11.1/hallo.xml.
<?xml version="1.0" encoding="ISO-8859-1"?>
<hallo>
<gruss>Hallo Welt! Dies ist XSLT.</gruss>
</hallo>
Both documents are processed with the same stylesheet gruss.xsl. The instruction <xsl:value-of select="gruss"/> is intended to copy the text content of <gruss> to the result document:
Code example: kap01/1.11.1/gruss.xsl.
<xsl:template match="/">
<html>
...
<body>
<h1 align="center">Dies ist ein Ergebnisdokument.</h1>
<p align="center"><xsl:value-of select="gruss"/></p>
</body>
</html>
</xsl:template>
For the first variant of the new source documents, the result looks as expected:
Code example: kap01/1.11.1/gruss.html.
<html>
...
<body>
<h1 align="center">Dies ist ein Ergebnisdokument.</h1>
<p align="center">Hallo Welt! Dies ist XSLT.</p>
</body>
</html>
For the second, however, it does not:
Code example: kap01/1.11.1/hallo.html.
<html>
...
<body>
<h1 align="center">Dies ist ein Ergebnisdokument.</h1>
<p align="center"></p>
</body>
</html>
Clearly, xsl:value-of failed to extract the text in the second case. This does not mean that the instruction was not executed; it simply found nothing. Why is that?
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