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 ...

Get Sams Teach Yourself XML in 10 Minutes 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.