Re: [xsl] Specify/determine element's "logical" parent

Subject: Re: [xsl] Specify/determine element's "logical" parent
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Thu, 23 Sep 2004 20:29:59 +0100
Hi John,

Is this possible and/or a bad idea?  I read that XPath statements
cannot be dynamic, so I imagine I have to use parentid attributes
rather than parentpath, then somehow map the ID to an actual node;
does that make sense? I also see the potential for infinite
recursion; any suggestions on that topic would be appreciated.

It would certainly be easiest to use the parentid attribute. To do that, all you have to do is set up a key that indexes the <item> elements based on their id attribute:


<xsl:key name="items" match="item" use="@id" />

and to get the parent of a particular item, use the key() function with the parentid attribute:

key('items', @parentid)

Parsing XPath using XSLT is possible but difficult. You're probably best off using an extension dyn:evaluate() function to do so. If you're using a small subset of XPath then you can alternatively use recursive templates to step through the path and parse it as you go. See my reply in the thread "generate-id for identical elements" for an example of how that might be done.

I'm not sure where the infinite recursion might occur, unless you want to get the parent of the parent once you find it?

Cheers,

Jeni
--
Jeni Tennison
http://www.jenitennison.com

Current Thread