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 ...

Get Special Edition Using XSLT now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.