|
 |
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 .
|
 |
|
|
 |

January 5th, 2010, 09:36 AM
|
Friend of Wrox
|
|
Join Date: Jul 2006
Location: , , .
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
|
|
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.
|

January 5th, 2010, 09:49 AM
|
 |
Wrox Author
Points: 18,487, Level: 59 |
|
|
Join Date: Apr 2004
Location: Reading, Berks, United Kingdom.
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
|
|
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:
|
|

January 5th, 2010, 09:50 AM
|
 |
Friend of Wrox
|
|
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
|
|
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/
|
The Following User Says Thank You to samjudson For This Useful Post:
|
|

January 5th, 2010, 09:51 AM
|
Friend of Wrox
|
|
Join Date: Jul 2006
Location: , , .
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
|
|
Thanks Michael & Sam. That was plan "b".
Regards,
|

January 5th, 2010, 10:22 AM
|
Friend of Wrox
|
|
Join Date: Jul 2006
Location: , , .
Posts: 430
Thanks: 28
Thanked 5 Times in 5 Posts
|
|
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.
|
Thread Tools |
Search this Thread |
|
|
Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
 |