O'Reilly logo

Sams Teach Yourself XML in 10 Minutes by Andrew H. Watt

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Creating New Attributes

To create a new attribute in the output document, you need to use the xsl:attribute element.

On this occasion, you will transform a source document in the U.K. company’s format to an XML output document in the U.S. company’s format. Listing 11.9 shows an XSLT stylesheet that can carry out the transformation.

Listing 11.9. UKShirtsToUS.xsl: An XSLT Stylesheet to Transform to the U.S. Company’s Data Format
<?xml version='1.0'?> 
<xsl:stylesheet 
 version="1.0" 
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
 > 
<xsl:output method="xml" indent="yes" encoding="UTF-8" /> 
<xsl:template match="/"> 
<USShirts> 
<Order> 
<xsl:apply-templates select="/UKShirts" /> 
</Order> 
</USShirts> 
</xsl:template> 

<xsl:template match="Order" > <xsl:apply-templates ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required