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

Re: What's wrong with my ancestor syntax?

Subject: Re: What's wrong with my ancestor syntax?
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 27 Mar 2007 17:18:52 +0100
Re:  What's wrong with my ancestor syntax?
>> 	<xsl:for-each select="//menuItem[pageID =  
>> $pageID]/descendant-or-self::menuItem"> 

>I think it says:
>
>Select any menuItem (//menuItem)
>That has a pageID of x ([pageID = $pageID])
>And is or is a descendant of said page (/descendant-or-self::menuItem)
>
>Did I get that about right? 

No, you have to read each step of an xpath in the context of where you
ended up at the last step (er, rather like walking:-)

so you read it as
Select any menuItem (//menuItem)That has a pageID of x ([pageID = $pageID])
Then FROM THERE select that node and any descendant menuItem nodes (descendant-or-self::menuItem),
return the resulting set of nodes.

This is just the same as an xpath of
/a/b/c
which means select all child a
then from those nodes, select all child b 
then from there select all child c nodes
return the resulting node set (or sequence in xpath 2)

whenever you see an an xpath of the form //blrgh[fidget=$wibble] you
should be asking yourself whether you should be using instead
<xsl:key name="x" match="blrgh" use="fidget"/>
...
  select="key('x',$wibble)"

since an key essentially just tells the system to optimise such lookups,
but get working first, before optimising!

David

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.