xsl-list
[Top] [All Lists]

Re: [xsl] Tokenized String Sorting Puzzle/Problem

2008-03-26 06:40:36
<xsl:stylesheet version="2.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>

<xsl:param name="s" select="'1 0 2 1 1 2 1 3 1 4 2 0 1 1 2 3 2 4 6 0 5 0 10 0 
10 1 10 2'"/>

<xsl:template name="main">
<xsl:for-each-group select="tokenize($s,'\s+')" group-by="(position()-1) idiv 
2">
  <xsl:sort select="number(current-group()[1])"/>
  <xsl:sort select="number(current-group()[2])"/>
: <xsl:value-of select="current-group()"/>
</xsl:for-each-group>
</xsl:template>

</xsl:stylesheet>


$ saxon9 -it main sort.xsl
<?xml version="1.0" encoding="UTF-8"?>
: 1 0
: 1 1
: 1 2
: 1 3
: 1 4
: 2 0
: 2 1
: 2 3
: 2 4
: 5 0
: 6 0
: 10 0
: 10 1
: 10 2




David


________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. 
________________________________________________________________________

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--