Chapter 6 - We Want Results! | |
XSLT For Dummies | |
by Richard Wagner | |
Hungry Minds 2002 |
Renaming an element is another technique that involves the use of literal text and xsl:value-of combination. Suppose, for example, that I want to rename the taste element to description in the coffee-light.xml . Within the stylesheet, I can create a single template rule to perform this operation: <!-- coffee-rename.xsl --> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"> <!-- Rename taste to description --> <xsl:template match="taste"> <description><xsl:value-of select="."/></description> </xsl:template> </xsl:stylesheet> The template rule uses a match pattern of taste to return all taste elements. The xsl:value-of instruction, with its select value of . , converts the content of each taste element to a string. The result is the following document: <?xml version="1.0" encoding="utf-8"?> <coffee name="Guatemalan Express" origin="Guatemala"> <description>Curiously Mild And Bland</description> <price>11.99</price> <availability>Year-round</availability> <bestwith>Breakfast</bestwith> </coffee>
|