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

Re: Accessing the Nth Occurrence of an Element

Subject: Re: Accessing the Nth Occurrence of an Element
From: David Carlisle <davidc@xxxxxxxxx>
Date: Tue, 16 Sep 2008 12:25:42 +0100
Re:  Accessing the Nth Occurrence of an Element
> b) the -or-self part of the // axis is pointless when starting at the root

Actually I think I mislead you there.


two reasons, 

firstly //foo  always selects the same nodes as
decendant::foo even if used as a relative xpath. Because there is an
implied child axis in the final step.

//self::foo selects the same nodes as /descendant-or-self::foo


secondly you have to be careful about trees whose root node is an
element. If the current node is such a parentless foo element then
descendant::foo will not select the element, descendant-or-self::foo
will select the element and //foo is an error
 XPDY0050: The root of the tree containing the context item is not a document node





<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 

<xsl:variable name="x" as="element()">
 <foo a="1">
  <foo a="2"/>
  <foo a="3"/>
 </foo>
</xsl:variable>


<xsl:template name="main">
 <xsl:for-each select="$x">

<!--A:  <xsl:value-of select="//foo/@a"/>-->
B:  <xsl:value-of select="root()//foo/@a"/>
C:  <xsl:value-of select="root()//self::foo/@a"/>
<!--D:  <xsl:value-of select="/descendant::foo/@a"/>-->
E:  <xsl:value-of select="root()/descendant::foo/@a"/>
<!--F:  <xsl:value-of select="/descendant-or-self::foo/@a"/>-->
G:  <xsl:value-of select="root()/descendant-or-self::foo/@a"/>
 </xsl:for-each>
</xsl:template>

</xsl:stylesheet>



B:  2 3
C:  1 2 3

E:  2 3

G:  1 2 3

________________________________________________________________________
The Numerical Algorithms Group Ltd is a company registered in England
and Wales with company number 1249803. The registered office is:
Wilkinson House, Jordan Hill Road, Oxford OX2 8DR, United Kingdom.

This e-mail has been scanned for all viruses by Star. The service is
powered by MessageLabs. 
________________________________________________________________________

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.