xsl-list
[Top] [All Lists]

Re: Finding the "correct" context node in a for-each with multiple predicates

2003-07-07 09:02:36
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[(_at_)location=<attribute value from
spot>]/bar[(_at_)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[(_at_)location = current()/@value]
                    /bar[(_at_)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



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