Writing Attribute Values

There are several ways to write attribute values to output documents in XSLT, and the most powerful one is to create attributes from scratch with the <xsl:attribute> element you’ll see in Chapter 6. However, you can also use attribute value templates for many purposes, and I’ll take a look at them in this chapter.

For example, suppose that you want to convert the text in the elements such as <MASS>, <DAY>, and <NAME> to attributes of <PLANET> elements, converting planets.xml to this form:

 <?xml version="1.0" encoding="UTF-8"?> <PLANETS> <PLANET DAY="58.65 days" RADIUS="1516 miles" MASS=".0553 (Earth = 1)" NAME="Mercury"/> <PLANET DAY="116.75 days" RADIUS="3716 miles" MASS=".815 (Earth = 1)" NAME="Venus"/> <PLANET DAY="1 ...

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.