I have a couple of huge XMLs and I need to sort only a some small portions of them. As output I should have the same XML but with sorted substructures. Here is an example:
<testStructure>
<parentStruct>
<firstpPreChild>some value here</firstpPreChild>
<secondPreChild>some other value</secondPreChild>
<thirdPreChild>third value here</thirdPreChild>
<fourtPreChild>fourth value here</fourtPreChild>
<struct id="5">
<num>5</num>
</struct>
<struct id="4">
<num>4</num>
</struct>
<struct id="1">
<num>1</num>
</struct>
<struct id="2">
<num>2</num>
</struct>
<struct id="3">
<num>3</num>
</struct>
<firstAdditionalChild>some value here</firstAdditionalChild>
<secondAdditionalChild>some other value</secondAdditionalChild>
<thirdAdditionalChild>third value here</thirdAdditionalChild>
<fourtAdditionalChild>fourth value here</fourtAdditionalChild>-->
</parentStruct>
<otherStruct>
<firstChild>some value here</firstChild>
<secondChild>some other value</secondChild>
<thirdChild>third value here</thirdChild>
<fourtChild>fourth value here</fourtChild>
</otherStruct>
应转换为
<testStructure>
<parentStruct>
<firstpPreChild>some value here</firstpPreChild>
<secondPreChild>some other value</secondPreChild>
<thirdPreChild>third value here</thirdPreChild>
<fourtPreChild>fourth value here</fourtPreChild>
<struct id="1">
<num>1</num>
</struct>
<struct id="2">
<num>2</num>
</struct>
<struct id="3">
<num>3</num>
</struct>
<struct id="4">
<num>4</num>
</struct>
<struct id="5">
<num>5</num>
</struct>
<firstAdditionalChild>some value here</firstAdditionalChild>
<secondAdditionalChild>some other value</secondAdditionalChild>
<thirdAdditionalChild>third value here</thirdAdditionalChild>
<fourtAdditionalChild>fourth value here</fourtAdditionalChild>-->
</parentStruct>
<otherStruct>
<firstChild>some value here</firstChild>
<secondChild>some other value</secondChild>
<thirdChild>third value here</thirdChild>
<fourtChild>fourth value here</fourtChild>
</otherStruct>
as sort criteria can be used either num
or @id
.
I ve tried some variation like this:
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
这起作用,但将排序后的结构从其原始位置移位。不幸的是,我需要与输出相同的结构。
提前感谢您的帮助!