[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Re: Numbering 1st 2nd 3rd ...
Hi Spencer,
So you are stuck with XSTL 1.0? Let me give it a try. Someone already pointed out that 11..13 are exceptions to the mod 10 rule. This is the simplest I could think of and it works up to 1000 at least (didn't check every number though) and it may even work for higher numbers. Lucky thing: not a huge <xsl:choose>, just a tiny one. Mark the line that says: <xsl:with-param name="top" select="200" /> Set it to any value to extend the list. Every number from 1 to $top is output. You prob. only need the tiny piece that is called "ordinal". The stylesheet works with any input, as it does not do anything with the input. Have fun with it ;) <?xml version="1.0" encoding="UTF-8"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/> <xsl:template match="/" > <ordinals> <xsl:call-template name="sequence"> <xsl:with-param name="top" select="200" /> </xsl:call-template> </ordinals> </xsl:template> <!-- returns a node set of ord-nodes with all numbers up to a given top --> <xsl:template name="sequence" > <xsl:param name="top" /> <xsl:if test="$top > 1" > <xsl:call-template name="sequence"> <xsl:with-param name="top" select="$top - 1" /> </xsl:call-template> </xsl:if> <ord> <xsl:value-of select="$top" /> <xsl:call-template name="ordinal"> <xsl:with-param name="number" select="$top" /> </xsl:call-template> </ord> </xsl:template> <!-- gets ordinal of a number in english --> <xsl:template name="ordinal"> <xsl:param name="number" /> <xsl:choose> <xsl:when test="$number mod 100 = 11">th</xsl:when> <xsl:when test="$number mod 100 = 12">th</xsl:when> <xsl:when test="$number mod 100 = 13">th</xsl:when> <xsl:when test="$number mod 10 = 3">rd</xsl:when> <xsl:when test="$number mod 10 = 2">nd</xsl:when> <xsl:when test="$number mod 10 = 1">st</xsl:when> <xsl:otherwise>th</xsl:otherwise> </xsl:choose> </xsl:template> </xsl:stylesheet> Cheers, Abel Braaksma http://abelleba.metacarpus.com Steve wrote: Recursive algorithm? (template which starts at the first, and calls itself passing param = param + 1).
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|