2017-02-08 4 views
1

특정 요소를 정렬하기위한 요구 사항이 있습니다. 그러나 나는 어떻게 그렇게 할 것인지 모른다. 내가 본 XSLT를 시도했지만 원하는 출력을 얻을 수 없습니다. 입력 XML은 다음과 같이이다 :XSLT를 사용하여 요소 정렬

<SyncCredit xmlns="http://schema.XYZ.com/XYZOAGIS/2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" releaseID="9.2" versionID="2.12.3"> 
    <Data> 
    <AccountingNo>ERP_12344</AccountingNo> 
    <Credit> 
     <Header> 
     <Name>Supplier Bank</Name> 
     <Date>02-08-2017</Date> 
     </Header> 
     <Payment> 
     <ID>111</ID> 
     <Date>02-01-2017</Date> 
     <Transaction> 
      <BookNo>AA-111</BookNo> 
      <Creditor> 
      <PartyID> 
       <ID schemeName="PassportNo">1000</ID> 
      </PartyID> 
      </Creditor> 
     </Transaction> 
     <Transaction> 
      <BookNo>AA-111</BookNo> 
      <Creditor> 
      <PartyID> 
       <ID schemeName="TaxIdentificationNo">5000</ID> 
      </PartyID> 
      </Creditor> 
     </Transaction> 
     </Payment> 
     <Payment> 
     <ID>222</ID> 
     <Date>02-05-2017</Date> 
     <Transaction> 
      <BookNo>AA-111</BookNo> 
      <Creditor> 
      <PartyID> 
       <ID schemeName="BankPartyNo">4000</ID> 
      </PartyID> 
      </Creditor> 
     </Transaction> 
     <Transaction> 
      <BookNo>AA-111</BookNo> 
      <Creditor> 
      <PartyID> 
       <ID schemeName="DriverLicense">2000</ID> 
      </PartyID> 
      </Creditor> 
     </Transaction> 
     </Payment> 
    </Credit> 
    </Data> 
</SyncCredit> 

내 예상 출력은, 다음과 같이

<SyncCredit xmlns="http://schema.XYZ.com/XYZOAGIS/2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" releaseID="9.2" versionID="2.12.3"> 
    <Data> 
    <AccountingNo>ERP_12344</AccountingNo> 
    <Credit> 
     <Header> 
     <Name>Supplier Bank</Name> 
     <Date>02-08-2017</Date> 
     </Header> 
     <Payment> 
     <ID>111</ID> 
     <Date>02-01-2017</Date> 
     <Transaction> 
      <BookNo>AA-111</BookNo> 
      <Creditor> 
      <PartyID> 
       <ID schemeName="PassportNo">1000</ID> 
      </PartyID> 
      </Creditor> 
     </Transaction> 
     </Payment> 
     <Payment> 
     <ID>222</ID> 
     <Date>02-05-2017</Date> 
     <Transaction> 
      <BookNo>AA-111</BookNo> 
      <Creditor> 
      <PartyID> 
       <ID schemeName="DriverLicense">2000</ID> 
      </PartyID> 
      </Creditor> 
     </Transaction> 
     </Payment> 
     <Payment> 
     <ID>222</ID> 
     <Date>02-05-2017</Date> 
     <Transaction> 
      <BookNo>AA-111</BookNo> 
      <Creditor> 
      <PartyID> 
       <ID schemeName="BankPartyNo">4000</ID> 
      </PartyID> 
      </Creditor> 
     </Transaction> 
     </Payment> 
     <Payment> 
     <ID>111</ID> 
     <Date>02-01-2017</Date> 
     <Transaction> 
      <BookNo>AA-111</BookNo> 
      <Creditor> 
      <PartyID> 
       <ID schemeName="TaxIdentificationNo">5000</ID> 
      </PartyID> 
      </Creditor> 
     </Transaction> 
     </Payment> 
    </Credit> 
    </Data> 
</SyncCredit> 

채권자/PartyID/ID 요소가 그대로 다른 요소를 유지하면서 정렬한다. 그러나 정렬 된 채권자/PartyID/ID를 각 <Payment> 노드로 분할해야합니다. XSLT v2.0을 사용하고 있습니다. 내가 제대로 내가 가진 참조, 내가 얻을 출력에서 ​​<xsl:perform-sort> 사용/PartyID이/ID를 채권 금융을 정렬 할 수 있어요,하지만 이런 식이다 : 이것은 내 XSLT이다

<Payment> 
    <Transaction xmlns="http://schema.XYZ.com/XYZOAGIS/2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <BookNo>AA-111</BookNo> 
    <Creditor> 
     <PartyID> 
     <ID schemeName="PassportNo">1000</ID> 
     </PartyID> 
    </Creditor> 
    </Transaction> 
    <Transaction xmlns="http://schema.XYZ.com/XYZOAGIS/2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <BookNo>AA-111</BookNo> 
    <Creditor> 
     <PartyID> 
     <ID schemeName="DriverLicense">2000</ID> 
     </PartyID> 
    </Creditor> 
    </Transaction> 
    <Transaction xmlns="http://schema.XYZ.com/XYZOAGIS/2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <BookNo>AA-111</BookNo> 
    <Creditor> 
     <PartyID> 
     <ID schemeName="BankPartyNo">4000</ID> 
     </PartyID> 
    </Creditor> 
    </Transaction> 
    <Transaction xmlns="http://schema.XYZ.com/XYZOAGIS/2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> 
    <BookNo>AA-111</BookNo> 
    <Creditor> 
     <PartyID> 
     <ID schemeName="TaxIdentificationNo">5000</ID> 
     </PartyID> 
    </Creditor> 
    </Transaction> 

, 그것은 완료되지 않은 I 때문에 Header 및 Payment.i에서 요소를 복사하는 방법을 알지 못합니다. 트랜잭션 요소에서 XSLT 만 시도했습니다.

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="2.0" xpath-default-namespace="http://schema.XYZ.com/XYZOAGIS/2"> 
<xsl:output method="xml" omit-xml-declaration="yes" indent="no"/> 
<xsl:template match="/"> 
    <xsl:variable name="Transaction"> 
     <xsl:perform-sort select="SyncCredit/Data/Credit/Payment/Transaction"> 
      <xsl:sort data-type="number" select="Creditor/PartyID/ID"/> 
     </xsl:perform-sort> 
    </xsl:variable> 
    <Payment> 
     <xsl:copy-of select="$Transaction"/> 
    </Payment> 
</xsl:template> 

은 사전에 감사합니다. 나는이 상황을 제대로 이해한다면

+0

2.0은 우리에게 당신이 시도한 XSLT를 표시합니다. –

+0

질문이 명확하지 않습니다. 출력은 입력과 다른 _structure_를 보여줍니다. 입력에서 각각 ''은 _0을' '을 포함하고 있지만 예상되는 출력에서 ​​각 트랜잭션은 자체 지불 노드로 나뉘어져 있습니다. –

+0

@ 짐 수비대 : 고마워. 이미 내 게시물을 편집하고 내가 만든 XSLT를 포함 시켰습니다. 네, 맞습니다. 입력시 지불 태그에는 2 개의 트랜잭션 태그가 있습니다. 내가 필요로하는 것은 채권자/PartyID/ID를 분류하고 그 자신의 지불 노드로 분할해야한다는 것입니다. –

답변

0

, 당신은하고 싶지 :

XSLT

<xsl:stylesheet version="2.0" 
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
xpath-default-namespace="http://schema.XYZ.com/XYZOAGIS/2" 
xmlns="http://schema.XYZ.com/XYZOAGIS/2"> 
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> 
<xsl:strip-space elements="*"/> 

<!-- identity transform --> 
<xsl:template match="@*|node()"> 
    <xsl:copy> 
     <xsl:apply-templates select="@*|node()"/> 
    </xsl:copy> 
</xsl:template> 

<xsl:template match="Credit"> 
    <xsl:copy> 
     <xsl:copy-of select="Header"/> 
     <xsl:apply-templates select="Payment/Transaction"> 
      <xsl:sort select="Creditor/PartyID/ID" data-type="number" order="ascending"/> 
     </xsl:apply-templates> 
    </xsl:copy> 
</xsl:template> 

<xsl:template match="Transaction"> 
    <Payment> 
     <xsl:copy-of select="../ID, ../Date, ."/> 
    </Payment> 
</xsl:template> 

</xsl:stylesheet> 
+0

안녕하세요, @ michael.hor257k, 예, 이해가 정확합니다. 귀하의 의견에 진심으로 감사드립니다. 매우 감사. 나는 이미 예상 된 결과를 얻었다. 정말 고맙습니다. –