[XSL-LIST Mailing List Archive Home] [By Thread] [By Date]

Re: [xsl] templates as functions that return a context?


Subject: Re: [xsl] templates as functions that return a context?
From: Joern Nettingsmeier <nettings@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 25 Feb 2006 00:20:46 +0100

hi david!


thanks for your quick reply.


David Carlisle wrote:
As far as I can see you need the name attribute of the nearest ancestor
rng:element or rng:attribute element.

You don't need to use a recursive template in an rtf for that, just
something like

select="(ancestor::rng:element|ancestor::rng:attribute)[last()]/@name"

you are right for this particular case. but the point i was (poorly) trying to make is that i want to encapsulate this somehow, since i need this function in many different places, combined with other tasks.


imagine the xpath that does "find the nearest ancestor that is an <element> or an <attribute> and determine whether this is enclosed in an <optional> tag, but without any other <element> or <attribute> tags in between", and soon you will long for the expressiveness and power of assembler or brainfuck :-D

if i coded everything "in-place", i.e. directly in my matching templates, everything would be possible, but the code will become a horrible mess, with lots of duplication. so i tried to do it in named templates, following the "don't repeat yourself" principle.

the orthogonal set of operations i want is:

* find the parent output node (i.e. <element> or <attribute>
* generate an id for a node (and this will eventually not be a "generate-id()" thing, but an id constructed from the xpath to the current node)
* determine whether a node is <optional>
* determine whether a node is in a repeater (<oneOrMore> etc.)


the actual tasks i have are always "find the parent output node and generate an id for that node", etc., i.e. combinations of those operations.

(i have also tried to do without the "backtracking" from leaf nodes and start the processing in element|attribute nodes, but the resulting code is a lot messier, has an awful lot of conditionals and is a lot less robust.)

to reiterate more clearly: is there any way to return a "node in context" from a template, or can this be done with xsl2 functions?
from a quick web search i would guess that xsl2 can do it, but has anyone here been using it successfully? saxon looks very promising, but xalan does not yet seem to implement it...



best,


jC6rn



--
jC6rn nettingsmeier

home://germany/45128 essen/lortzingstr. 11/
http://spunk.dnsalias.org
phone://+49/201/491621

if you are a free (as in "free speech") software developer
and you happen to be travelling near my home, drop me a line
and come round for a free (as in "free beer") beer. :-D


Current Thread
Keywords