xsl-list
[Top] [All Lists]

lookup table keyed by position

2005-02-23 13:02:59
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


--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



<Prev in Thread] Current Thread [Next in Thread>