View Single Post
  #1 (permalink)  
Old February 11th, 2019, 12:05 PM
pedromcerveirapinto pedromcerveirapinto is offline
Registered User
Points: 12, Level: 1
Points: 12, Level: 1 Points: 12, Level: 1 Points: 12, Level: 1
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Feb 2019
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
Default Sort portion of XML File

Good day,
I'm new to the forum and to XSLT Transformations. I've read a similar post to mine but found no answer.
I have a rather large XML file which I need sorted in some blocks.
The XML structure file is:
<AuditFile>
<GeneralLedgerEntries>
<Journal>
<Transaction>
<Lines>
<DebitLine>
</DebitLine>
<CreditLine>
</CreditLine>
</Lines>
</Transaction>
</Journal>
</GeneralLedgerEntries>
</AuditFile>

Where inside Lines we can have any number of CreditLines and/or DebitLine and in whatever order, that is we can have them interchanging.
I need this Lines block sorted so that I have all CreditLines and only after that all DebitLines.
Furthermore this Lines block repeats along the file.
Could you please help me?

My poor attempt at getting this done was as follows:
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>

<!-- Sort Lines -->
<xsl:template match="Lines">
<Lines>
<xsl:apply-templates>
<xsl:sort select="name()"/>
</xsl:apply-templates>
</Lines>

</xsl:template>

Hope you can help me.
Thanks.
Reply With Quote