Sortuj XML do XML za pomocą XSLT
Znalazłem kilka podobnych pytań, ale starałem się „zgiąć” rozwiązanie tego, czego potrzebuję, więc przepraszam za ponowne pytanie.
Mam trochę takiego XML ....
<?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>
Napisałem ten 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>
(Z tego wyciągnąłem zarys tegojak sortować xml?)
To, co chcę zrobić, to użyć tego XSLT, aby posortować mój oryginalny XML przez atrybut id elementu1 i wygenerować XML. Pomysł polega na tym, że po jego posortowaniu mogę przetworzyć inny XSLT, aby uzyskać ostateczny wynik.
Niestety nie daje mi to żadnego wyjścia, co sprawia, że myślę, że jest naprawdę głupia literówka. gdzieś, ale nie widzę tego.
Każda pomoc byłaby doceniana.
Dzięki