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 January 5th, 2010, 09:36 AM
Friend of Wrox
 
Join Date: Jul 2006
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.
 
Old January 5th, 2010, 09:49 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
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
The Following User Says Thank You to mhkay For This Useful Post:
bonekrusher (January 5th, 2010)
 
Old January 5th, 2010, 09:50 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
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?
The Following User Says Thank You to samjudson For This Useful Post:
bonekrusher (January 5th, 2010)
 
Old January 5th, 2010, 09:51 AM
Friend of Wrox
 
Join Date: Jul 2006
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,
 
Old January 5th, 2010, 10:22 AM
Friend of Wrox
 
Join Date: Jul 2006
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.





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





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