Renaming an Element

 
xslt for dummies
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> 
  
 
 
2000-2002    Feedback


XSLT For Dummies
XSLT for Dummies
ISBN: 0764536516
EAN: 2147483647
Year: 2002
Pages: 148

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net