954,568 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

XML Transformation using XSLT

Hi,

I need to do some sorting of the XML file. First, group the group_1 first and then sort those group_1 block by SORT_ID and Salary. Second, group the group_2 and then sort those group_2 block by SORT_ID.

I just try the below and it works if the XML only have group_1..........
***********************************************************


Input XML
************************************************************
HillPhil100000104/23/1999HerbertJohnny95000209/01/1998HillPhil100000104/23/1999MTonyGraham89000108/20/2000JackJohnny100000209/01/1998

Output XML
************************************************************
<?xml version="1.0" encoding="UTF-16"?>
TonyGraham8900008/20/20001HillPhil10000004/23/19991HerbertJohnny9500009/01/19982JackJohnny10000009/01/19982M

Any suggestion?
Thanks.

AOTONY

aotonyleung
Newbie Poster
2 posts since Nov 2008
Reputation Points: 10
Solved Threads: 0
 

You were nearly there. Try the following stylesheet on your sample document

<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:output method="text"/>

<xsl:template match="text()" />

<xsl:template match="allgroup">
   <xsl:apply-templates>
       <xsl:sort select="name()" />
       <xsl:sort select="SORT_ID" data-type="number"/>
       <xsl:sort select="salary" data-type="number" order="descending"/>
   </xsl:apply-templates>
</xsl:template>

<xsl:template match="last" >
   GROUP: <xsl:value-of select="name(..)"/> SORT_ID: <xsl:value-of select="../SORT_ID"/> SAL: <xsl:value-of select="../s
alary" /> NAME: <xsl:value-of select="." />, <xsl:value-of select="../first" />
</xsl:template>

</xsl:stylesheet>

which will output

GROUP: group_1 SORT_ID: 1 SAL: 100000 NAME: Hill, Phil
  GROUP: group_1 SORT_ID: 1 SAL: 89000 NAME: Tony, Graham
  GROUP: group_1 SORT_ID: 2 SAL: 100000 NAME: Jack, Johnny
  GROUP: group_1 SORT_ID: 2 SAL: 95000 NAME: Herbert, Johnny
  GROUP: group_2 SORT_ID: 1 SAL: 100000 NAME: Hill, Phil
fpmurphy
Junior Poster
147 posts since Oct 2008
Reputation Points: 22
Solved Threads: 11
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You