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

RE: preceding-sibling inside for-each appears to fail

Subject: RE: preceding-sibling inside for-each appears to fail
From: Sandeep_Karandikar@xxxxxxxx
Date: Mon, 10 Feb 2003 09:13:57 -0600
following sibling
Is there any known way of using these predefined API's in context of a
node-set ?

I have been trying to use these in the context of a node-set traversal using
<xsl:for-each select="Node-set"> to determine unique elements in the
node-set ?

-Sandeep.

-----Original Message-----
From: Michael Kay [mailto:michael.h.kay@xxxxxxxxxxxx]
Sent: Monday, February 10, 2003 4:33 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE:  preceding-sibling inside for-each appears to fail


> What I'm having a little difficulty understanding is exactly why 
> preceding-sibling, in this example, requires a positional predicate 
> while following-sibling doesn't. Also, I thought that the node-set 
> returned by the select attribute in the for-each element was 
> complete.

When you do
<xsl:value-of select="xxxxx-sibling::*"/>
or
<xsl:value-of select="xxxxx-sibling::*[1]"/>

there are several effects interacting.

Firstly, the XPath expression xxxx-sibling::node() selects a set of
nodes. The XSLT <xsl:value-of> instruction ignores all the nodes in the
set except the one that is first in document order. So <xsl:value-of
select="following-sibling::*"/> gives you the immediately following
sibling, while <xsl:value-of select="preceding-sibling::*"/> gives you
the _first_ (most distant) preceding sibling.

Secondly, a filter used within a step is applied to nodes in terms of
their distance from the context node. The filter [1] selects the node
that is closest to the context node. So following-sibling::*[1] selects
the immediately following sibling, while preceding-sibling::*[1] selects
the immediately preceding (least distant) sibling.

(Note the "within a step". If your write (preceding-sibling::*)[1], then
the [1] is no longer within a step. A filter that is outside a step
considers nodes in document order, so this expression will select the
first (most distant) preceding sibling.)

This explains why adding the filter "[1]" to the instruction
<xsl:value-of select="following-sibling::*"/> makes no difference to the
outcome, while adding it in the preceding-sibling case makes a big
difference.

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx 


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list



 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.