RE: [xsl] XPath equivalent of a join

Subject: RE: [xsl] XPath equivalent of a join
From: "Michael Kay" <mike@xxxxxxxxxxxx>
Date: Sat, 14 Jul 2007 15:32:17 +0100
You can't really ask "is there an XPath statement" without specifying XPath
1.0 or 2.0. XPath 1.0 has no range variables, which makes some joins
difficult or impossible to express, but 2.0 is relationally complete. The
most direct way of coding this in XPath 2.0 (given <root> as the context
node) is something like:

for $t in teacher[gender='female']/@id
return class[teacher = $t]

To get good performance (i.e. better than O(m*n)) you can use keys in XSLT,
or find an XPath implementation such as the one in Saxon-SA that does join
optimization. (You're more likely to find XQuery implementations doing join
optimization than XSLT implementations, because XQuery vendors tend to have
approached things more from the database perspective rather than the
document perspective.)

Michael Kay
http://www.saxonica.com/
 

> -----Original Message-----
> From: Aaron Luke [mailto:bluenike@xxxxxxxxx] 
> Sent: 14 July 2007 11:28
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] XPath equivalent of a join
> 
> Hi all-
> 
> Given the following document:
> 
> <root>
>   <class id="1">
>     <teacher>5</teacher>
>   </class>
>   <class id="2">
>     <teacher>9</teacher>
>   </class>
> 
>   <teacher id=5>
>     <gender>female</gender>
>   </teacher>
>   <teacher id=9>
>     <gender>male</gender>
>   </teacher>
> </root>
> 
> Is there an XPath statement that selects all of the classes 
> taught by female teachers (in this case, just the first class)?
> The field class.teacher is an id reference to teacher.id.
> 
> In sql, I would be looking for:
> 
> select class.* from class c, teacher t where c.teacher=t.id 
> and t.gender='female';
> 
> Can't seem to figure this one out- any help would be appreciated.
> 
> Aaron

Current Thread