[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] collapsing number ranges

Subject: Re: [xsl] collapsing number ranges
From: Bruce D'Arcus <bdarcus@xxxxxxxxxxxxx>
Date: Sat, 28 Aug 2004 23:32:38 -0400

OK, I took David's stylesheet and modified it to see if I could tackle the Chicago page number collapsing algorithm.

Here's the output the algorithm is dictating (and ideally, if not a huge hassle, I want):


Here's what I actually get:


So the tricky examples are what the algorithm describes in English as

1) numbers that begin with a multiple of 100 do not get collapsed
2) "110 through 199, 210 through 299, etc.", where one uses "two or more digits as needed" for the end part of the range.
3) "if three digits change in a four-digit number, use all four."

Any suggestions on how to modify the below to cover this?

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"

<xsl:variable name="x">
  <x a="71" b="72"/>
  <x a="100" b="104"/>
  <x a="200" b="204"/>
  <x a="101" b="108"/>
  <x a="321" b="328"/>
  <x a="1087" b="1089"/>

<xsl:template match="/">
  <xsl:apply-templates select="$x/x"/>

<xsl:template match="x">
:<xsl:value-of select="@a"/>-<xsl:value-of select="x:number-range(@a,@b)"/>

<xsl:function name="x:number-range">
<xsl:param name="begin" as="xs:integer"/>
<xsl:param name="end"/>
<xsl:when test="$begin gt 100">
<xsl:value-of select= "if ($begin idiv 10 = $end idiv 10) then () else
(x:number-range($begin idiv 10,$end idiv 10)), ($end mod 10)" separator=""/>
<xsl:value-of select="$end"/>


Current Thread