Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 5th, 2010, 09:36 AM
Friend of Wrox
Points: 1,676, Level: 16
Points: 1,676, Level: 16 Points: 1,676, Level: 16 Points: 1,676, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2006
Location: , , .
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default Sorting by Roman Numerals

Hi,

Is it possible to sort by roman numeral?

Suppose my xml is:
Code:
<part title="PAPERS" chapter="CHAPTER II/>
<part title="PAPERS" chapter="CHAPTER I/>
<part title="PAPERS" chapter="CHAPTER III/>
<part title="PAPERS" chapter="CHAPTER IV/>
Xslt Fragment:
Code:
<xsl:for-each-group select="part" group-by="@chapter">
            <xsl:sort select="current-grouping-key()" case-order="upper-first" order="ascending" data-type="text"/>
This will result as

Code:
CHAPTER III
CHAPTER II
CHAPTER I
CHAPTER IV
Desired Result:
Code:
CHAPTER I
CHAPTER II
CHAPTER III
CHAPTER IV
Thanks for the help.
Reply With Quote
  #2 (permalink)  
Old January 5th, 2010, 09:49 AM
mhkay's Avatar
Wrox Author
Points: 18,487, Level: 59
Points: 18,487, Level: 59 Points: 18,487, Level: 59 Points: 18,487, Level: 59
Activity: 100%
Activity: 100% Activity: 100% Activity: 100%
 
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

In theory an implementation could provide a collation that understands roman numerals, but I think it's unlikely that any implementation does so.

I think you will have to write a function that translates roman numerals to numbers, and then sort on the resulting number. It shouldn't be too difficult.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
Reply With Quote
The Following User Says Thank You to mhkay For This Useful Post:
bonekrusher (January 5th, 2010)
  #3 (permalink)  
Old January 5th, 2010, 09:50 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

I suspect you will have the only way to do this would be to provide your own custom collation and sorting algorymth using an extension script.

If you are using Saxon you could read this article, which gives some details of how custom collations are loaded by Saxon (see the Custom Compare at the end of the article).

http://www.ibm.com/developerworks/xm...x-xsltsorting/
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
Reply With Quote
The Following User Says Thank You to samjudson For This Useful Post:
bonekrusher (January 5th, 2010)
  #4 (permalink)  
Old January 5th, 2010, 09:51 AM
Friend of Wrox
Points: 1,676, Level: 16
Points: 1,676, Level: 16 Points: 1,676, Level: 16 Points: 1,676, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2006
Location: , , .
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Thanks Michael & Sam. That was plan "b".

Regards,
Reply With Quote
  #5 (permalink)  
Old January 5th, 2010, 10:22 AM
Friend of Wrox
Points: 1,676, Level: 16
Points: 1,676, Level: 16 Points: 1,676, Level: 16 Points: 1,676, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2006
Location: , , .
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
Send a message via Yahoo to bonekrusher
Default

Sam,

Great link. I created a class to do the custom sorting for Saxon:

here is a copy if any needs one:

Code:
package xsltcollations;

import java.text.ParseException;
import java.text.RuleBasedCollator;

public class RomanNumeralCollation extends RuleBasedCollator {

    public RomanNumeralCollation() throws ParseException {
        super(romanNumerals);
    }

    private static String romanNumerals = ("< I < II < III < IV < V < VI< VII <" +
            "VIII < IX <X <XI <XII <XIII <XIV <XV <XVI <XVII <XVIII <XIX <XX" +
            " < XXI < XXII < XXIII < XXIV < XXV < XXVI < XXVII < XXVIII <XXIX <" +
            " XXX < XXXI< XL< L < LX< LXX < LXXX < XC < C < CI " +
            "< CL < CC < CCC < CD < D < DC <DCC <DCCC <CM <M < MDC < MDCC <MCM");
}
Thanks again.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sorting nguna XSLT 1 August 27th, 2009 09:59 AM
How to set font Roman 10cpi in Crystal Reports Rajesh.Prajapat C# 0 October 14th, 2008 06:14 AM
Numerals into figures renu2214 Classic ASP Professional 0 April 17th, 2007 09:34 AM
Please Help Me sorting this nj.nikhil BOOK: Beginning ASP 3.0 1 November 10th, 2006 03:45 PM
Datagrid sorting by non alphabetical sorting? LLAndy VS.NET 2002/2003 1 July 15th, 2004 01:20 AM



All times are GMT -4. The time now is 05:36 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.