这种转变:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:param name="pOrder" select=
"'|LocatorDesignator|LocatorName|Locator|thoroughfare|addressArea|'"/>
<xsl:variable name="vOrder" select="document('')/*/xsl:param[@name='pOrder']/*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Rowinfo">
<xsl:copy>
<xsl:apply-templates select="*">
<xsl:sort data-type="number" select=
"string-length(substring-before($pOrder, concat('|', name(), '|')))"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
当应用于以下 XML 文档时(由您上一个问题的答案产生):
<Address>
<Rowinfo>
<Locator>1</Locator>
<LocatorDesignator>Null, Dwelling (Part Of)</LocatorDesignator>
<thoroughfare>Abesinia Passage</thoroughfare>
<LocatorName>Dwelling (Part Of)</LocatorName>
<addressArea>Some Address Area</addressArea>
</Rowinfo>
<Rowinfo>
<Locator>1a</Locator>
<LocatorDesignator>Null, Edmund's Home</LocatorDesignator>
<thoroughfare>Arena's Palace Lane</thoroughfare>
<LocatorName>Edmund's Home</LocatorName>
<addressArea>Some Other Address Area</addressArea>
</Rowinfo>
</Address>
产生想要的正确结果:
<Address>
<Rowinfo>
<LocatorDesignator>Null, Dwelling (Part Of)</LocatorDesignator>
<LocatorName>Dwelling (Part Of)</LocatorName>
<Locator>1</Locator>
<thoroughfare>Abesinia Passage</thoroughfare>
<addressArea>Some Address Area</addressArea>
</Rowinfo>
<Rowinfo>
<LocatorDesignator>Null, Edmund's Home</LocatorDesignator>
<LocatorName>Edmund's Home</LocatorName>
<Locator>1a</Locator>
<thoroughfare>Arena's Palace Lane</thoroughfare>
<addressArea>Some Other Address Area</addressArea>
</Rowinfo>
</Address>