The following example
transforms an XML document into another XML document.
This is the input XML
document named XMLInput.xml, which contains data about vehicles. Each
second-level repeating element describes a particular car, with the
nested elements that contain information about the model and year.
The make information is an attribute on the second-level repeating
element.
<?xml version="1.0" ?>
<vehicles>
<car make="Ford">
<model>Mustang</model>
<year>1965</year>
</car>
<car make="Chevrolet">
<model>Nova</model>
<year>1967</year>
</car>
</vehicles>
This is the XSL style
sheet named XSLTransform.xsl that describes how to transform the XML.
The conversion creates <root> as the root-enclosing element
and <model> as the second-level repeating element. Each <model>
element in the output XML document will include the values from the
<car> element and the make= attribute from the input XML document.
<?xml version="1.0" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/vehicles">
<root> <xsl:apply-templates select="car"/> </root>
</xsl:template>
<xsl:template match="car">
<model make="{@make}">
<xsl:value-of select="model" />
</model>
</xsl:template>
</xsl:stylesheet>