Re: [xsl] Need help with using lookup table and string translation
Subject: Re: [xsl] Need help with using lookup table and string translation|
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Mon, 11 May 2009 16:47:22 -0400
At 03:40 PM 5/11/2009, you wrote:
The 'for in' looks like xslt2 function.
I MUST do this with XSLT 1
This is important because its for a browser-based transformations and
I need the template to work on most browsers.
That's why I have not even looked at all the XSLT2 functions yet.
At fist I thought about using named template and use call-template but
now I think it's not necessary and I can just create a normal template
for the <trs> element
You can certainly do this.
and inside that template do all the logic of finding the correct
result for the value of the element.
Unfortunately, if you are limited to unextended XSLT 1.0, you will
have trouble doing this.
The reason is that lookups of the sort you want are rather tricky in
XSLT 1.0. Good solutions depend on either
(a) an extension function such as exsl:node-set(), not supported by
all browsers, or
(b) the document() function, which can call in an external source (or
even acquire the stylesheet itself as a document) to provide the lookup
Unfortunately, even the document() function, although it is standard,
is not universally supported, and you might want to test your XSLT
engine(s) before relying on it.
Without one of these mechanisms, both of which provide for ways to
work around the "result tree fragment" restriction in XSLT 1.0 (which
prevents you from querying into arbitrary node sets the way you query
into the source document tree), you're going to be reduced to
brute-force processing (think series of xsl:when statements) -- not
pleasant or graceful.
Assuming you can use one of these, how to implement a lookup table in
XSLT is fairly easily discovered using a search engine.
The document('') idiom might be your best bet. See
http://www.ibm.com/developerworks/library/x-xsltip.html for an example.
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