Subject: RE: [xsl] collapsing number ranges From: <Jarno.Elovirta@xxxxxxxxx> Date: Fri, 27 Aug 2004 11:59:41 +0300 |
Hi, > 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" /> Can't really see what you algorithm is, but here's a wild guess, just call x:range('23-24') <xsl:function name="x:range"> <xsl:param name="range" as="xs:string"/> <xsl:variable name="first" select="substring-before($range, '-')"/> <xsl:variable name="second" select="substring-after($range, '-')"/> <xsl:sequence select="concat($first, '-', x:remove($first, $second, 1))"/> </xsl:function> <xsl:function name="x:remove"> <xsl:param name="s1" as="xs:string"/> <xsl:param name="s2" as="xs:string"/> <xsl:param name="i" as="xs:integer"/> <xsl:sequence select="if (substring($s1, $i, 1) = substring($s2, $i, 1)) then x:remove($s1, $s2, $i + 1) else if (string-length($s2) < 3) then substring($s2, $i) else substring($s2, $i - 1)"/> </xsl:function> Cheers, Jarno - Rotersand: Merging Oceans
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] collapsing number ranges, Michael Kay | Thread | RE: [xsl] collapsing number ranges, David . Pawson |
RE: [xsl] collapsing number ranges, J-P S | Date | Re: [xsl] collapsing number ranges, Jeni Tennison |
Month |