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

Re: collapsing number ranges

Subject: Re: collapsing number ranges
From: Bruce D'Arcus <bdarcus@xxxxxxxxxxxxx>
Date: Sat, 28 Aug 2004 23:32:38 -0400
chicago page number collapsing algorithm
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


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.
First Name
Last Name
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-2013 All Rights Reserved.