[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: Finding the "correct" context node in a for-each w

Subject: Re: 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
xsl for each context
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

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.