Thank you Martin! I need to unravel the select clause on the grouping; there
are some concepts I donbt understand.
From: Martin Honnen martin.honnen@xxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Sent: Friday, June 5, 2026 10:57 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: Algorithm for determining ranges
On 05/06/2026 16:47, rick@xxxxxxxxxxxxxx <mailto:rick@xxxxxxxxxxxxxx> wrote:
Hi Martin,
The last number is where the ranges should be. Thank you.
I need to determine ranges, like this:
<?xml version="1.0" encoding="UTF-8"?>
<xrefs>
<xref>16.1.0</xref>
<xref>16.2.1</xref>
<range/>
<xref>16.2.3</xref>
<xref>16.14.2</xref>
<xref>16.22.0</xref>
</xrefs>
I am trying to determine an XSLT 3.0 algorithm for doing this. I am looking
for suggestions. Thank you in advance.
For the test sample
<xsl:template match="xrefs">
<xsl:copy>
<xsl:for-each-group select="xref" group-adjacent="let $numbers :=
tokenize(., '\.') ! xs:integer(.) return string-join(($numbers[position() lt
last()], $numbers[last()] - position() + 1), '.')">
<xsl:choose>
<xsl:when test="current-group()[3]">
<xsl:sequence select="current-group()[1]"/>
<range/>
<xsl:sequence select="current-group()[3]"/>
</xsl:when>
<xsl:otherwise>
<xsl:sequence select="current-group()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</xsl:copy>
</xsl:template>
would do.
Not sure whether at some point e.g. 16.2.9 and 16.3.0 would form a range.
XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <http://lists.mulberrytech.com/unsub/xsl-list/612310> (by
email <> )
|