This is the XML that I am trying to sort:
<?xml version="1.0" encoding="utf-8"?>
<Proposal>
<MobileKey>test string</MobileKey>
<RevisionNumber>9</RevisionNumber>
<CreationDate>2014-04-30T13:21:00</CreationDate>
<ProposalDueDate>test string</ProposalDueDate>
<ProposalJobs>
<ProposalID>56</ProposalID>
<ProposalRevision>9</ProposalRevision>
<ProposalJobNumber>9</ProposalJobNumber>
<ServiceLine>test string</ServiceLine>
<SubServiceLine>test string</SubServiceLine>
</ProposalJobs>
<ProposalJobs>
<ProposalID>42</ProposalID>
<ProposalRevision>9</ProposalRevision>
<ProposalJobNumber>9</ProposalJobNumber>
<ServiceLine>test string</ServiceLine>
<SubServiceLine>test string</SubServiceLine>
</ProposalJobs>
<ProposalJobs>
<ProposalID>21</ProposalID>
<ProposalRevision>9</ProposalRevision>
<ProposalJobNumber>9</ProposalJobNumber>
<ServiceLine>test string</ServiceLine>
<SubServiceLine>test string</SubServiceLine>
</ProposalJobs>
</Proposal>
The output should be (sorted on ProposalID):
<?xml version="1.0" encoding="utf-8"?>
<Proposal>
<MobileKey>test string</MobileKey>
<RevisionNumber>9</RevisionNumber>
<CreationDate>2014-04-30T13:21:00</CreationDate>
<ProposalDueDate>test string</ProposalDueDate>
<ProposalJobs>
<ProposalID>21</ProposalID>
<ProposalRevision>9</ProposalRevision>
<ProposalJobNumber>9</ProposalJobNumber>
<ServiceLine>test string</ServiceLine>
<SubServiceLine>test string</SubServiceLine>
</ProposalJobs>
<ProposalJobs>
<ProposalID>42</ProposalID>
<ProposalRevision>9</ProposalRevision>
<ProposalJobNumber>9</ProposalJobNumber>
<ServiceLine>test string</ServiceLine>
<SubServiceLine>test string</SubServiceLine>
</ProposalJobs>
<ProposalJobs>
<ProposalID>56</ProposalID>
<ProposalRevision>9</ProposalRevision>
<ProposalJobNumber>9</ProposalJobNumber>
<ServiceLine>test string</ServiceLine>
<SubServiceLine>test string</SubServiceLine>
</ProposalJobs>
</Proposal>
I have used the following XSLT. It does the sorting correctly but deletes all the child elements of Proposal
except the ProposalJobs
nodes. Please help me out here:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://ift.tt/tCZ8VR"
xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl"
>
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
<xsl:template match="Proposal">
<xsl:copy>
<xsl:apply-templates select="@*"/>
<xsl:apply-templates select="ProposalJobs">
<xsl:sort select="ProposalID"/>
</xsl:apply-templates>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
No comments:
Post a Comment