[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Reranging Numbers

Subject: Re: Reranging Numbers
From: Jeff Sese <jeferson.sese@xxxxxxxxxxxx>
Date: Tue, 21 Sep 2010 16:33:04 +0800
Re:  Reranging Numbers
Works perfectly, thanks!

-- Jeff

On 09 21, 10, at 3:56 PM, Michael Kay wrote:

First parse the string and convert to a sequence of integers, something like:

<xsl:for-each select="tokenize(., ',\s+')">
<xsl:choose>
<xsl:when test="contains(., '-')">
<xsl:sequence select="xs:integer(substring-before(., '-') to xs:integer(substring-after(., '-')"/>
</
<xsl:otherwise>
<xsl:sequence select="xs:integer(.)"/>
</
</
</


Then do grouping using a method first suggested by David Carlisle on this list:

<xsl:for-each-group select="..." group-adjacent=". - position()">
<xsl:choose>
<xsl:when test="count(current-group()) gt 1">
<xsl:value-of select="current-group()[1], current-group()[last()]" separator="-"/>
</
<xsl:otherwise>
<xsl:value-of select="current-group()[1]"/>
</
</
</


On 21/09/2010 8:09 AM, Jeff Sese wrote:
Hi,

If i have a node like:

<node>1, 2, 3, 5-8, 9, 11, 15</node>

How can I make it as:

<node>1-3, 5-9, 11, 15</node>

I'm using XSLT 2.0

Thanks,
-- Jeff

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2011 All Rights Reserved.