Altering Document Structure Based on Input

So far, the templates in this chapter have been fairly rigid skeletons, specifying exactly what should go into the output document in what order. But you can use XSLT elements such as <xsl:element>, <xsl:attribute>, <xsl:text>, and so on to create new nodes on the fly, based on what you find in the input document. I'll take a look at how this works now.

Creating Attribute Templates

Say that you wanted to convert the text in some elements to attributes in other elements—how could you do it? Attribute values must be quoted in XML, but you can't just use expressions like these, where I'm taking the values of <NAME>, <MASS>, and <DAY> elements and trying to make them into attribute values:

 <xsl:template ...

Get Inside XML 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.