xsl-list
[Top] [All Lists]

Re: collapsing number ranges

2004-08-27 02:21:57
Hi Bruce,

Is there some easy way -- in XSLT 2.0 -- to handle in a general way
collapsing number ranges like:

23-24 => 23-4
333-334 => 333-34
7777-7778 => 7777-78

The source will be like:

<biblioref linkend="one" units="page" begin="23" end="24" />

Taking a guess at the algorithm, what about:

  <xsl:value-of select="@begin" />
  <xsl:text>-</xsl:text>
  <xsl:choose>
    <xsl:when test="string-length(@begin) = 1">
      <xsl:value-of select="@end" />
    </xsl:when>
    <xsl:when test="string-length(@begin) = 2">
      <xsl:value-of select="substring(@end, 2, 1)" />
    </xsl:when>
    <xsl:otherwise>
      <xsl:value-of select="substring(@end, last() - 1)" />
    </xsl:otherwise>
  </xsl:choose>

If that's not what you're after, show us the XML of some more examples
and try to put the algorithm that you want into English or
pseudo-code.
  
Cheers,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



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