Subject: Re: Hash / Translation Tables (the right way)
From: Michael Kay <mike@xxxxxxxxxxxx>
Date: Mon, 26 Sep 2011 00:00:29 +0100
|
On 25/09/2011 23:40, G. Ken Holman 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.
That's common practice but I've never seen any advantage over using a
separate document.
Michael Kay
Saxonica
|