O'Reilly logo

Special Edition Using XSLT by Michael Floyd

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding New Template Rules

The style sheets presented thus far have used <value-of> to retrieve the content of top-level elements and attributes. However, the XML document instance in Listing 2.1 also contains subelements, namely, the address element:

<invoice num=”2317” invoiceDate=”07-09-01”> 
    ... 
    <address> 
        <streetAddress>123 Fourth Street</streetAddress> 
        <city>Sometown</city> 
        <state>CA</state> 
        <zip>12345</zip> 
        <province /> 
        <country>USA</country> 
    </address> 
   ... 
</invoice> 

To retrieve the content from, say, <streetAddress>, you could assign a step pattern in the select attribute of a <value-of> element. That might look something like:

<xsl:value-of select="invoice/address/streetAddress" /> 

This approach works fine for this example because ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required