| Subject: Re: [xsl] Finding the "correct" context node in a for-each with multiple predicates From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx> Date: Mon, 7 Jul 2003 17:02:36 +0100 | 
Hi Mikael,
> Now I want to to work through the set of nodes in the spot list that
> match the select I'm trying to describe below:
>
> <xsl:for-each select="spot[foo[@location=<attribute value from
> spot>]/bar[@type=<attribute name from spot>]]">
>
> So the question is how do I access the attributes of the spot
> currently under test?
You can't do it in a single XPath, particularly since the <foo>
elements are in a different document. You could split the XPath up as
in:
  <xsl:variable name="foos" select="document('other.xml')/foos/foo" />
  <xsl:for-each select="spot">
    <xsl:if test="$foos[@location = current()/@value]
                    /bar[@type = current()/@name]">
      ...
    </xsl:if>
  </xsl:for-each>
(If you have lots of spots and bars then for efficiency you might
consider using a key to get hold of the relevant one.)
If you really need to do it in a single XPath (for example because you
want to count how many <spot> elements there are) then you should
consider doing one of:
  1. creating a result tree fragment that only contains the <spot>
     elements you're interested in, and converting that to a node-set
  2. combining the two documents into one so that you can access the
     relevant <bar> elements via a key within the predicate
  3. creating a stylesheet function (via func:function from EXSLT)
     that tests whether the <spot> element is relevant or not, and
     using a call to that function in the predicate
Cheers,
Jeni
---
Jeni Tennison
http://www.jenitennison.com/
 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
| Current Thread | 
|---|
| 
 | 
| <- Previous | Index | Next -> | 
|---|---|---|
| Re: [xsl] Finding the "correct" con, David Carlisle | Thread | Re: RE: [xsl] number total of page, a.robert21@xxxxxxxxx | 
| Re: [xsl] Finding the "correct" con, David Carlisle | Date | Re: [xsl] identity transform - incl, Abie Hamaoui | 
| Month |