xsl-list
[Top] [All Lists]

Re: [xsl] Reranging Numbers

2010-09-21 03:33:19
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


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




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






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

<Prev in Thread] Current Thread [Next in Thread>