XPath query to recurse up the tree

Subject: XPath query to recurse up the tree
From: Ian Sutton <ian.sutton@xxxxxxxxxxx>
Date: Thu, 17 Aug 2000 14:58:44 +0100
Am I missing something, or is the current definition of XPath queries (or
whatever the current name is) limited to recursion down the tree?

As an example, consider an XML document representing a file system with
<directory> nodes which can contain either <file> nodes or further
<directory> nodes. (Case I have is actually nothing to do with filesystems
but this seems the simplest way to represent the issue.)

Given a current context of a directory, I could find all child file nodes
recursively with

<xsl:apply-templates select=".//file" /> 

and a corresponding template rule.

I have a case where my <directory> nodes have certain additional attributes
(lets say optional TYPE=something) and I wish to find the first parent which
has say TYPE=X. Is there any way to do this? 

I kind of half guess it may be possible to do something like a recursive
call with an apply templates select=".." mode="myUpwardRecursion" and write
a specific template match rule which tests the attribute and either returns
or recurses up, but this seems fairly painful if indeed it would work at
all.

Any answers/ideas gratefuly received ;->

Ian


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread