我有幾個巨大的XML,我只需要對它們中的一小部分進行排序。 作爲輸出我應該有相同的XML,但有子結構。 下面是一個例子:使用XSLT排序的XML到XML
<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>
爲排序規則可用於任一num
或@id
。 我已經嘗試了一些變化是這樣的:
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
它的工作原理,但是從原來的位置移到了有序結構。不幸的是我需要和輸出一樣的結構。
在此先感謝您的幫助!
你希望如果有什麼的''元素不是相鄰的,但有其他的孩子? –