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 October 14th, 2005, 09:46 AM
Authorized User
 
Join Date: Jun 2003
Posts: 57
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Kabe
Default sorting based on substring-before

have this xml:
<EL>aa_123</EL>
<EL>aa_456</EL>
<EL>bb_987</EL>
<EL>cc_111</EL>
<EL>cc_222</EL>
<EL>cc_333</EL>
(this is really kind of data i've to handle)

want to (sub)sort this like this:
aa: 123,456
bb: 987
cc: 111,222,333

have already this:
<xsl:key name="prefix" match="EL" use="substring-before(.,'_')"/>
<xsl:for-each select="EL[count(.| key('prefix',@name)[1]) = 1]">
...
</xsl:for-each>

sort like this now:
aa,aa,bb,cc,cc,cc

but should be (each different substring-before value once):
aa,bb,cc
 
Old October 14th, 2005, 09:54 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

A problem that involves combining duplicates is a grouping problem not (primarily) a sorting problem. Grouping is easy in XSLT 2.0 using <xsl:for-each-group>, but much harder in XSLT 1.0: see http://www.jenitennison.com/xslt/grouping for ideas.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference





Similar Threads
Thread Thread Starter Forum Replies Last Post
Delete option(s) based on substring of value Lori713 Javascript How-To 3 February 7th, 2008 09:00 AM
Pls help - Sorting based on condition kalwinhobbess Crystal Reports 0 September 10th, 2007 10:47 AM
sorting based on an index TheBFJ Excel VBA 4 November 21st, 2006 05:31 AM
Sorting data in to groups based on rules cube VB.NET 0 April 11th, 2006 06:44 PM
Sorting based on formula in group footer NixyJ Crystal Reports 0 August 27th, 2004 06:37 AM





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