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

Elements just before/after the current one

Subject: Elements just before/after the current one
From: Nicolas Pillot <nicolas.pillot@xxxxxxxxxx>
Date: Thu, 27 May 2004 14:40:28 -0400
preceding sibling xsl
  Hello!

  I have a problem, as you can guess. I am struggling to find the element
  that is just before, and the element just after the current one.

  What i am doing now for the element after the current one is :
     following-sibling::*[position() = 1]
  And this seems to work. But for the element just before, i tried
     following-sibling::*[last()]
  but this gives me the first (topmost) item instead of the last !
  So i debugged with :

	<xsl:variable name="prevcount">
		<xsl:value-of select="count(preceding-sibling::*)" />
	</xsl:variable>
	<xsl:for-each select="preceding-sibling::*">
		<xsl:element name="before">	
			<xsl:value-of select="."/> <!-- or name() -->
			<xsl:value-of select="position()"/>
			<xsl:if test="position() = $prevcount">
				selected
			</xsl:if>
		</xsl:element>
	</xsl:for-each>

  And the "selected" text appears right next to the good element.
  Then i tried the following to sum it up :

	<xsl:variable name="prevcount">
		<xsl:value-of select="count(preceding-sibling::*)" />
	</xsl:variable>
	<xsl:value-of select="preceding-sibling::*[position() = $prevcount]" />

  But again, it give me the content of the first (topmost) node !!
  What am i doing wrong ?! Is there a simpler way to get these "special" items ?

  Any help would be greatly appreciated !
  Nicolas

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.