Newbie struggling with XSLT....
Given the below xml file, I want to create a new xml file that transposes the <town> and <company> elements in the result tree, then sorts by ascending town and company/name (alternately, I'd like to sort by ascending town and
company/name/@id). The result of my transform is the original xml file (I haven't figured out the transpose part, and the result tree is unsorted).
Any help is greatly appreciated!
XML:
<?xml version="1.0" encoding="UTF-16"?>
<?xml-stylesheet type="text/xsl" href="Sort Test.xsl" ?>
<company_data>
<company id="EFGH">
<name>EFGH Company</name>
<town>Somewhere</town>
<phone>888-888-8888</phone>
<web_address> </company>
<company id="ABCD">
<name>ABCD Company</name>
<town>Tranquil</town>
<phone>123-456-7890</phone>
<web_address> </company>
<company id="LLLL">
<name>LLLL Company</name>
<town>Sydney</town>
<phone></phone>
<web_address> </company>
</company_data>
XSLT:
<?xml version="1.0" encoding="UTF-16"?>
<xsl:stylesheet xmlns:xsl="version="1.0">
<xslutput method="xml" indent="yes" />
<xsl:template match="company_data">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates>
<xsl:sort select="company/name" />
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="node() | @*">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
Given the below xml file, I want to create a new xml file that transposes the <town> and <company> elements in the result tree, then sorts by ascending town and company/name (alternately, I'd like to sort by ascending town and
company/name/@id). The result of my transform is the original xml file (I haven't figured out the transpose part, and the result tree is unsorted).
Any help is greatly appreciated!
XML:
<?xml version="1.0" encoding="UTF-16"?>
<?xml-stylesheet type="text/xsl" href="Sort Test.xsl" ?>
<company_data>
<company id="EFGH">
<name>EFGH Company</name>
<town>Somewhere</town>
<phone>888-888-8888</phone>
<web_address> </company>
<company id="ABCD">
<name>ABCD Company</name>
<town>Tranquil</town>
<phone>123-456-7890</phone>
<web_address> </company>
<company id="LLLL">
<name>LLLL Company</name>
<town>Sydney</town>
<phone></phone>
<web_address> </company>
</company_data>
XSLT:
<?xml version="1.0" encoding="UTF-16"?>
<xsl:stylesheet xmlns:xsl="version="1.0">
<xslutput method="xml" indent="yes" />
<xsl:template match="company_data">
<xsl:apply-templates/>
</xsl:template>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates>
<xsl:sort select="company/name" />
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="node() | @*">
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>