I am new to XSL and trying to get a grasp of the language. I need to
totally reformat some xml files and have a question about node paths.
Example XML file:
<?xml version="1.0" encoding="UTF-8"?>
<AAA>
<DDD id="test1">
<BBB>10</BBB>
<CCC>ccc</CCC>
<BBB>5</BBB>
<BBB>7</BBB>
</DDD>
<DDD id="test2">
<BBB>1</BBB>
<BBB>2</BBB>
<CCC>ccc</CCC>
<BBB>3</BBB>
</DDD>
</AAA>
What I want to new XML file to look like:
<?xml version="1.0" encoding="UTF-8"?>
<AAA>
<DDD>
<BBB num="test1">10</BBB>
<BBB num="test1">5</BBB>
<BBB num="test1">7</BBB>
</DDD>
<DDD>
<BBB num="test2">1</BBB>
<BBB num="test2">2</BBB>
<BBB num="test2">3</BBB>
</DDD>
</AAA>
My XSL file:
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="AAA">
<xsl:element name="AAA">
<xsl:apply-templates select="DDD" />
</xsl:element>
</xsl:template>
<xsl:template match="DDD">
<xsl:element name="DDD">
<xsl:apply-templates select="BBB"></xsl:apply-templates>
</xsl:element>
</xsl:template>
<xsl:template match="BBB">
<xsl:element name="BBB">
<xsl:attribute name="num">
<xsl:value-of select="//DDD/@id"></xsl:value-of>
</xsl:attribute>
<xsl:value-of select="."></xsl:value-of>
</xsl:element>
</xsl:template>
</xsl:stylesheet>
Thanks,
Michael
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list