모든 ShippingPoint가 먼저 정렬 된 다음 첫 번째 ShippingPoint에 따라 Cargos가 첫 번째 ShippingPoint에 따라 마지막으로 TransportPoint에 따라 예제 XML을 정렬해야합니다 뱃짐. 그래서 기본적으로 나는 그들이 시작되기로되어있는 날짜에 따라 모든 수송선을 분류하려고 시도하고 있습니다.XML을 재귀 적으로 정렬 - 내부 노드 만 정렬합니다.
이제 Cargos 및 ShippingPoints 만 예상대로 정렬된다는 점을 제외하고는 XSL 재귀를 사용하여 솔루션을 찾았습니다. 가장 외부의 전송 노드는 아닙니다. 내가 여기서 뭘 잘못하고 있는지 궁금해. MSXML (VS2008)과 Saxon 파서는 똑같은 결과를줍니다.
예제 XML 코드 :
<?xml version="1.0" encoding="utf-8"?>
<Transports>
<Transport ID="1893">
<Cargos>
<Cargo ID="1532" >
<ShippingPoints>
<ShippingPoint ID="1600" ArrivesOn="2011-04-07T12:00:00" />
<ShippingPoint ID="1601" ArrivesOn="2011-04-08T12:00:00" />
</ShippingPoints>
</Cargo>
<Cargo ID="1532">
<ShippingPoints>
<ShippingPoint ID="1601" ArrivesOn="2011-03-08T12:00:00" />
<ShippingPoint ID="1600" ArrivesOn="2011-02-07T12:00:00" />
</ShippingPoints>
</Cargo>
</Cargos>
</Transport>
<Transport ID="1891" >
<Cargos>
<Cargo ID="1529" >
<ShippingPoints>
<ShippingPoint ID="1594" ArrivesOn="2011-04-14T12:00:00" />
<ShippingPoint ID="1595" ArrivesOn="2011-04-04T13:00:00" />
</ShippingPoints>
</Cargo>
<Cargo ID="1530" >
<ShippingPoints>
<ShippingPoint ID="1597" ArrivesOn="2011-04-09T18:00:00" />
<ShippingPoint ID="1596" ArrivesOn="2011-04-04T12:00:00" />
</ShippingPoints>
</Cargo>
</Cargos>
</Transport>
<Transport ID="1892">
<Description/>
<Cargos>
<Cargo ID="1531" >
<ShippingPoints>
<ShippingPoint ID="1599" ArrivesOn="2011-04-06T18:00:00" />
<ShippingPoint ID="1598" ArrivesOn="2011-04-05T12:00:00" />
</ShippingPoints>
</Cargo>
<Cargo ID="1531" >
<ShippingPoints>
<ShippingPoint ID="1599" ArrivesOn="2011-04-02T18:00:00" />
<ShippingPoint ID="1598" ArrivesOn="2011-04-03T12:00:00" />
</ShippingPoints>
</Cargo>
</Cargos>
</Transport>
</Transports>
XSLT 코드 :
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output method="xml" version="1.0" encoding="UTF-8" />
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="ShippingPoints">
<xsl:copy>
<xsl:apply-templates select="ShippingPoint">
<xsl:sort select="@ArrivesOn" />
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="Cargos">
<xsl:copy>
<xsl:apply-templates select="Cargo">
<xsl:sort select="ShippingPoints/ShippingPoint[1]/@ArrivesOn" />
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
<xsl:template match="Transports">
<xsl:copy>
<xsl:apply-templates select="Transport">
<xsl:sort select="Cargos/Cargo[1]/ShippingPoints/ShippingPoint[1]/@ArrivesOn"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
그 트릭을 했어 - 간단하고 깨끗한. 감사! – dawidw
@ dawidw : 천만에. –