Subject: Re: [xsl] lookup table keyed by position From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx> Date: Wed, 23 Feb 2005 15:09:17 -0500 |
I tried to build a lookup table that would convert 2-digit month numbers to their 3-letter abbreviation like this:
<xsl:variable name="months"> <abbrev>Jan</abbrev> <abbrev>Feb</abbrev> <abbrev>Mar</abbrev> <abbrev>Apr</abbrev> <abbrev>May</abbrev> <abbrev>Jun</abbrev> <abbrev>Jul</abbrev> <abbrev>Aug</abbrev> <abbrev>Sep</abbrev> <abbrev>Oct</abbrev> <abbrev>Nov</abbrev> <abbrev>Dec</abbrev> </xsl:variable>
And given a variable in YYYY-MM-DD format, I can get the abbreviation with this expression:
$months/abbrev[number(substring($yyyy-mm-dd, 6, 2))]
Then I tried to index the table like this:
<xsl:key name="months-by-position" match="abbrev" use="position()"/>
And look up the abbreviation with this expression:
key('months-by-position', number(substring($yyyy-mm-dd, 6, 2)), $months)
But my output indicates that for all of the '02' through '12' numbers, the key function returns an empty sequence, and for '01' it returns a sequence of all the abbrev elements (which are serialized with a space between them).
It seems that the context node when position is evaluated is the months element, not the individual abbbrev elements. Can this be made to work as I want?
Cheers, Wendell
====================================================================== Wendell Piez mailto:wapiez@xxxxxxxxxxxxxxxx Mulberry Technologies, Inc. http://www.mulberrytech.com 17 West Jefferson Street Direct Phone: 301/315-9635 Suite 207 Phone: 301/315-9631 Rockville, MD 20850 Fax: 301/315-8285 ---------------------------------------------------------------------- Mulberry Technologies: A Consultancy Specializing in SGML and XML ======================================================================
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
[xsl] lookup table keyed by positio, Kevin Rodgers | Thread | RE: [xsl] lookup table keyed by pos, Michael Kay |
Re: [xsl] xsl recursion, Dimitre Novatchev | Date | Re: [xsl] xsl transform issue, dan sherman |
Month |