Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 4th, 2010, 06:23 AM
Authorized User
 
Join Date: Feb 2009
Posts: 31
Thanks: 6
Thanked 1 Time in 1 Post
Send a message via MSN to anil_yadav26@hotmail.com
Default [XSTL] Sorting

Hi,

I have an XML file in which pages are appearing under the <link> tag. I want to sort those pages in ascending order. I'm doing the same with an XSLT but the result is not up to the mark.

I'm sorting the page numbers following page Numbers:

46, 56, 6, 64, 167, 176, 199, 203, 212, 248, 305, 315, 363

but the output is generating like this:

167, 176, 199, 203, 212, 248, 305, 315, 363, 46, 56, 6, 64

Whereas I need the output like this:

6, 46, 56, 64, 167, 176, 199, 203, 212, 248, 305, 315, 363

Can anybody suggest me how to rectify this?


XML File

Code:
<index-list>
<index-item><index-entry id="c51351-3902">aggression</index-entry><link>46</link><link>56</link><link>6</link><link>64</link><link>167</link><link>176</link><link>199</link><link>203</link><link>212</link><link>248</link><link>305</link><link>315</link><link>363</link></index-item>
</index-list>
Output generating
Code:
<index-list>
<index-item><index-entry id="c51351-3902">aggression</index-entry><link>167</link><link>176</link><link>199</link><link>203</link><link>212</link><link>248</link><link>305</link><link>315</link><link>363</link><link>46</link><link>56</link><link>6</link><link>64</link></index-item>
</index-list>
Output Required

Code:
<index-list>
<index-item><index-entry id="c51351-3902">aggression</index-entry><link>6</link><link>46</link><link>56</link><link>64</link><link>167</link><link>176</link><link>199</link><link>203</link><link>212</link><link>248</link><link>305</link><link>315</link><link>363</link></index-item>
</index-list>
XSLT
Code:
 <xsl:template match="index-item">
  <index-item>
   <xsl:copy-of select="@*"/>
   <xsl:if test="index-entry">
    <xsl:apply-templates select="index-entry"/>
   </xsl:if>
   <xsl:for-each select="link">
    <xsl:sort select="."/>
    <link>
     <xsl:copy-of select="@*"/>
     <xsl:value-of select="."/>
    </link>
   </xsl:for-each>
  </index-item>
 </xsl:template>
Regards,
Anil Yadav
 
Old March 4th, 2010, 06:26 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

<xsl:sort select="." data-type="number"/>
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
The Following User Says Thank You to samjudson For This Useful Post:
[email protected] (March 4th, 2010)
 
Old March 4th, 2010, 06:33 AM
Authorized User
 
Join Date: Feb 2009
Posts: 31
Thanks: 6
Thanked 1 Time in 1 Post
Send a message via MSN to anil_yadav26@hotmail.com
Thumbs up

Its working....!
Thanks a lot, samjudson!
 
Old March 4th, 2010, 06:42 AM
Authorized User
 
Join Date: Feb 2009
Posts: 31
Thanks: 6
Thanked 1 Time in 1 Post
Send a message via MSN to anil_yadav26@hotmail.com
Default

Hi samjudson,

Its working fine in case of number. But some of link tags contains range where it is not working.

e.g.

<index-item><index-entry>1/58 Stork v High ECR 17</index-entry>&#x2002;<link>232--233</link><link>23--230</link></index-item>

Could you please suggest me on the same?

Thanks,
Anil Yadav
 
Old March 4th, 2010, 06:50 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

<xsl:sort select="substring-before(concat(.,'-'),'-')" data-type="number"/>
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
The Following User Says Thank You to samjudson For This Useful Post:
[email protected] (March 4th, 2010)





Similar Threads
Thread Thread Starter Forum Replies Last Post
sorting nguna XSLT 1 August 27th, 2009 09:59 AM
Please Help Me sorting this nj.nikhil BOOK: Beginning ASP 3.0 1 November 10th, 2006 03:45 PM
SORTING pallone XSLT 3 October 29th, 2006 08:45 AM
XSTL help(shopping list) awjob XSLT 2 October 4th, 2005 08:31 AM
Datagrid sorting by non alphabetical sorting? LLAndy VS.NET 2002/2003 1 July 15th, 2004 01:20 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.