Access to node values

For access to values the <xsl:value-of> element with its obligatory select attribute is used. The template determines the position in the source tree. The select attribute of the <xsl:value-of> element determines which values are copied into the result tree. For example the access to the name, the content or the attributes of the nodes is possible. When choosing the current node, the . character can be used instead of the element name, which means that the content of the current element is outputted. When choosing attributes, the @ character in front of the attribute name is available. If an element with sub-elements is selected, possible subsequent templates without the call <xsl:apply-templates> are ignored and only the selected textual content is displayed. The following example shows this relation:

The stylesheet:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output encoding="iso-8859-1" version="1.0"/>
    <xsl:template match="CollectionOfPoems">
        <html>
            <body>
                <xsl:value-of select="."/>
            </body>
        </html>
    </xsl:template>
    <xsl:template match="Author">
        <br/>
        <h4>
            <xsl:apply-templates/>
        </h4>
    </xsl:template>
    <xsl:template match="FirstName">
        <xsl:apply-templates/>
        <xsl:text> </xsl:text>
    </xsl:template>
    <xsl:template match="LastName">
        <xsl:apply-templates/>
    </xsl:template>
    <xsl:template match="Title">
        <h2>
            <xsl:apply-templates/>
        </h2>
    </xsl:template>
    <xsl:template match="Strophe">
        <p>
           <xsl:apply-templates/>
        </p>
    </xsl:template>
    <xsl:template match="Verse">
        <xsl:apply-templates/>
        <br/>
    </xsl:template>
</xsl:stylesheet>

Browser view of the target document:

Browser view: example - value-of

Exercise 3

Rewrite the above stylesheet with the result that the YearOfPublication attribute of the Poem element is displayed.

> > to the solution of exercise 3

   

<< back next >>

 


Copyright © dpunkt.verlag GmbH 2004
Printing of the online version is permitted exclusively for private use. Otherwise this chapter from the book "XSL-FO in der Praxis" ("XSL-FO in practice") is subject to the same provisions as those applicable for the hardcover edition: The work including all its components is protected by copyright. All rights reserved, including reproduction, translation, microfilming as well as storage and processing in electronic systems.

dpunkt.verlag GmbH, Ringstraße 19B, 69115 Heidelberg, fon 06221-14830, fax 06221-148399, hallo@dpunkt.de