RE: XPath query to recurse up the tree

Subject: RE: XPath query to recurse up the tree
From: Kevin Williams <Kevin.Williams@xxxxxxxxxxxxxx>
Date: Thu, 17 Aug 2000 10:56:12 -0400
Ian,

Couldn't you use an XPath expression like the following?

ancestor::directory[@TYPE='X']

It's not recursion, really, since the chain of parentage is linear, but it
sounds like it'll do what you're asking for...

- Kevin

> -----Original Message-----
> From: Ian Sutton [mailto:ian.sutton@xxxxxxxxxxx]
> Sent: Thursday, August 17, 2000 9:59 AM
> To: 'XSL-List@xxxxxxxxxxxxxxxx'
> Subject: XPath query to recurse up the tree
> 
> 
> 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
> 


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


Current Thread