[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: J-P S <jps@xxxxxxxxxxxxxxxxxxxx>
Date: Fri, 27 Aug 2004 10:32:41 +0100 (BST)
cabron meaning
On Fri, 27 Aug 2004, Jeni Tennison wrote:

) > 7777-7778 => 7777-78
)
) Taking a guess at the algorithm, what about:
)
)   <xsl:value-of select="@begin" />
)   <xsl:text>-</xsl:text>
)   <xsl:choose>

Gah! Of course! xsl:choose, but with recursion. I'm always averse to
recursive template calls, but I think the below will work for the general
case. Call this template with your start and end numbers, and "0" for the
digit parameter (or "1" or "2" if you *know* the first one or two digits
will always be the same, to speed things up):

	<xsl:template name="number">

	  <xsl:param name="start" />
	  <xsl:param name="end"/>
	  <xsl:param name="digits"/>

	  <xsl:choose>

	    <!-- If strings are the same for first $digit digits, call
		self with $digit+1 and test again -->
	    <xsl:when test="substring($start,1,$digits) =
			substring($end,1,$digits)">
	      <xsl:call-template name="number">
	        <xsl:with-param name="start" select="$start"/>
	        <xsl:with-param name="end" select="$end"/>
	        <xsl:with-param name="digits" select="$digits+1"/>
	      </xsl:call-template>
	    </xsl:when>

	    <!-- If strings aren't the same, then print $start,
		followed by a dash, followed by the tail end of $end -->
	    <xsl:otherwise>
	      <xsl:value-of select="concat($start,'-',
			substring($end,$digits,string-length($end)))"/>
	    </xsl:otherwise>

	  </xsl:choose>

	</xsl:template>

Let me know how you get on!

Cheers,
J-P
-- 
(First Beep is cabron, meaning your wife is unfaithful.  Second Beep is
maricon, which means faggot. It is very simple to make out what he is
saying because the beeps do not delete the words completely and or in
combination with his lip movements you make out the words.)

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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.
Email
First Name
Last Name
Company
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.