I have a found a few similar questions to this, but struggled to 'bend' the solution to what I need, so apologies for asking again.
I have some XML like this:
<?xml version="1.0" encoding="UTF-8"?>
<ns:Root
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ns="urn:Test.Namespace"
xsi:schemaLocation="urn:Test.Namespace Test1.xsd"
>
<ns:element1 id="001">
<ns:element2 id="001.1" order="1">
<ns:element3 id="001.1.1" />
</ns:element2>
<ns:element2 id="001.2" order="2">
<ns:element3 id="001.1.2" />
</ns:element2>
</ns:element1>
<ns:element1 id="003">
<ns:element2 id="007.0" order="1">
<ns:element3 id="007.1.1" />
</ns:element2>
</ns:element1>
<ns:element1 id="002">
<ns:element2 id="002.1" order="3">
<ns:element3 id="002.1.1" />
</ns:element2>
<ns:element2 id="002.2" order="4">
<ns:element3 id="002.1.2" />
</ns:element2>
</ns:element1>
</ns:Root>
I have written this XSLT:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ns="urn:Test.Namespace"
>
<xsl:output indent="no" />
<xsl:template match="text()[not(string-length(normalize-space()))]"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:apply-templates>
<xsl:sort select="/ns:Root/ns:element1/@id" />
<xsl:copy-of select="." />
</xsl:apply-templates>
</xsl:template>
<xsl:template match="ns:element1">
<xsl:copy-of select="." />
<xsl:apply-templates />
</xsl:template>
<xsl:template match="ns:element2">
<xsl:copy-of select="." />
<xsl:apply-templates />
</xsl:template>
<xsl:template match="ns:element3">
<xsl:copy-of select="." />
</xsl:template>
</xsl:stylesheet>
(I cribbed the outline for this from here how to sort xml?)
What I want to be able to do, is use this XSLT to sort my original XML by the id attribute of element1 and produce XML.
The idea being that once it is sorted, I can process it with some other XSLT to get the final result.
Unfortunately, this does not give me any output, which makes me think there is a really stupid typo somewhere, but I cannot see it.