xsl-list
[Top] [All Lists]

RE: [xsl] XPath equivalent of a join

2007-07-14 07:32:48
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(_at_)gmail(_dot_)com] 
Sent: 14 July 2007 11:28
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
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

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: 
<mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>