Matching Attributes
As Chapter 3, “Creating and Using Templates,” showed, you can match attributes if you preface their names with an @. You’ve already worked with the UNITS attribute that most of the children of <PLANET> elements support:
<PLANET> <NAME>Earth</NAME> <MASS UNITS="(Earth = 1)">1</MASS> <DAY UNITS="days">1</DAY> <RADIUS UNITS="miles">2107</RADIUS> <DENSITY UNITS="(Earth = 1)">1</DENSITY> <DISTANCE UNITS="million miles">128.4</DISTANCE><!--At perihelion--> </PLANET>
To recover the units and display them as well as the values for the mass and so on, you can match the UNITS attribute with @UNITS, as follows:
Listing 4.1. Matching Attributes
<?xml version="1.0"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> ... |
Get Inside 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.