Subject: [xsl] lookup table keyed by position From: Kevin Rodgers <kevin.rodgers@xxxxxxx> Date: Wed, 23 Feb 2005 13:02:59 -0700 |
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? Thanks, -- Kevin Rodgers
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Navigating XML when loade, António Mota | Thread | Re: [xsl] lookup table keyed by pos, Wendell Piez |
Re: [xsl] xsl recursion, Dimitre Novatchev | Date | Re: [xsl] xsl recursion, Dimitre Novatchev |
Month |