|
[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
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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








