[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
Another approach is to have a document months.xml
then
document('months.xml')/months/month[@abbr=lower-case($mon)]/@num
(or instead of a separate document you can put the lookup table in a global variable in the stylesheet; but with XSLT 1.0 this relies on the node-set() function.)
On 25/09/2011 22:32, G. Ken Holman wrote:
Re: [xsl] Hash / Translation Tables (the right way)
Subject: Re: [xsl] Hash / Translation Tables (the right way) From: Michael Kay <mike@xxxxxxxxxxxx> Date: Sun, 25 Sep 2011 23:35:31 +0100 |
Another approach is to have a document months.xml
<months> <month name='January' abbr='jan' num='01'/> <month name='February' abbr='feb' num='02'/> ... </months>
then
document('months.xml')/months/month[@abbr=lower-case($mon)]/@num
(or instead of a separate document you can put the lookup table in a global variable in the stylesheet; but with XSLT 1.0 this relies on the node-set() function.)
Michael Kay Saxonica
On 25/09/2011 22:32, G. Ken Holman wrote:
At 2011-09-25 14:28 -0700, Hank Ratzesberger wrote:I'm having some problems with constructs like hash tables or indexes, which are quick in other languages but presently I am using some brute force with. E.G.
<xsl:template name="month-of"> <xsl:param name="mon"/> <xsl:choose> <xsl:when test="lower-case($mon) = 'jan'"> <xsl:value-of select="'01'"/> </xsl:when> <xsl:when test="lower-case($mon) = 'feb'"> <xsl:value-of select="'02'"/> </xsl:when> <xsl:when test="lower-case($mon) = 'mar'"> <xsl:value-of select="'03'"/> </xsl:when>
It seems there must be a way to accomplish this with a simple sequence. Months of the year, days of the week, and other one to one translations from the textual to ordinal or vice versa.
XSLT 1 (though not accommodating case):
format-number(
(string-length(substring-before('janfebmaraprmayjunjulaugsepoctnovdec',$mon) )
div 3) + 1,'00')
XSLT 2:
format-number( index-of( ('jan','feb',...,'dec'), lower-case($mon) ),'00' )
I hope this helps.
. . . . . . . . . Ken
-- Contact us for world-wide XML consulting and instructor-led training Crane Softwrights Ltd. http://www.CraneSoftwrights.com/s/ G. Ken Holman mailto:gkholman@xxxxxxxxxxxxxxxxxxxx Google+ profile: https://plus.google.com/116832879756988317389/about Legal business disclaimers: http://www.CraneSoftwrights.com/legal
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Hash / Translation Tables, G. Ken Holman | Thread | Re: [xsl] Hash / Translation Tables, G. Ken Holman |
Re: [xsl] Hash / Translation Tables, G. Ken Holman | Date | Re: [xsl] Client-side XSLT, Michael Kay |
Month |