Subject: RE: [xsl] Elements just before/after the current one From: "Josh Canfield" <Josh.Canfield@xxxxxxxxxxxx> Date: Thu, 27 May 2004 11:49:17 -0700 |
The first node in the preceding-sibling axis is the node nearest the current node, the last node would be the node furthest away. You want something like: <prev><xsl:value-of select="preceding-sibling::*[1]"/></prev> <next><xsl:value-of select="following-sibling::*[1]"/></next> Josh -----Original Message----- From: Nicolas Pillot [mailto:nicolas.pillot@xxxxxxxxxx] Sent: Thursday, May 27, 2004 11:40 AM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx Subject: [xsl] Elements just before/after the current one 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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Elements just before/afte, G. Ken Holman | Thread | RE: [xsl] Elements just before/afte, Nicolas Pillot |
[xsl] Elements just before/after th, Nicolas Pillot | Date | Re: [xsl] Elements just before/afte, Nicolas Pillot |
Month |