xsl-list
[Top] [All Lists]

Re: [xsl] What's wrong with my ancestor syntax?

2007-03-27 09:19:09
     <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



--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--