xsl-list
[Top] [All Lists]

Re: [xsl] Hash / Translation Tables (the right way)

2011-09-25 17:44:57
Except that my use of lower-case() earlier wouldn't work in XSLT 1. A common way to get lower-case in XSLT 1 is with the translate() function.

Please forgive my haste in my earlier answer.

. . . . . . . . . . Ken

At 2011-09-25 18:40 -0400, I wrote:
At 2011-09-25 23:35 +0100, Michael Kay wrote:

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.)

It can also be done in XSLT 1.0 without extensions by putting the structure in a namespace at the top level of the stylesheet:

   <hank:months>
     <month name='January' abbr='jan' num='01'/>
     <month name='February' abbr='feb' num='02'/>
     ...
   </hank:months>

... and using the document() function:

   document('')/*/hank:months/month[@abbr=lower-case($mon)]/@num

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(_at_)CraneSoftwrights(_dot_)com
Google+ profile: https://plus.google.com/116832879756988317389/about
Legal business disclaimers:    http://www.CraneSoftwrights.com/legal


--~------------------------------------------------------------------
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>
--~--