xsl-list
[Top] [All Lists]

RE: [xsl] Getting first child node postion with condition

2007-06-08 03:16:53
Thanks for your response, it works perfectly.

Cordially,
julien Flotté.

From: "Michael Kay" <mike(_at_)saxonica(_dot_)com>
Reply-To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Subject: RE: [xsl] Getting first child node postion with condition
Date: Fri, 8 Jun 2007 10:19:31 +0100

position() does not return the position of a selected node in the tree, it
returns the position of the current node within the list of nodes that are
currently being processed. You want either count() or xsl:number.

The simplest solution here is XSLT 2.0:

<xsl:number select="leaf[(_at_)attrib='true'][1]"/>

The equivalent in 1.0 is:

<xsl:for-each select="leaf[(_at_)attrib='true'][1]">
  <xsl:number/>
</xsl:for-each>

Or you can use count():

count(leaf[(_at_)attrib='true'][1]/preceding-sibling::leaf)+1

Michael Kay
http://www.saxonica.com/

> -----Original Message-----
> From: Julien Flotté [mailto:julien_flotte3(_at_)hotmail(_dot_)com]
> Sent: 08 June 2007 10:09
> To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
> Subject: [xsl] Getting first child node postion with condition
>
> Hi,
> I'm a french student in training course.
> I make development in xslt and I encounter the following problem :
>
> My xml file :
>
> <?xml version="1.0" encoding="UTF-8"?>
>
> <tree>
> <leaf attrib = 'false'>Leaf1</leaf>
> <leaf attrib = 'true'>Leaf2</leaf>
> <leaf attrib = 'true'>Leaf3</leaf>
> </tree>
>
> When I'm in the "tree" template, I want to get the position
> of the first child node with the attribute "attrib" equals
> "true" but I don't succeed.
>
> I attempt to use the postion function but it doesn't work :
> leaf[(_at_)attrib = 'true'][postion()] returns the value of the first child
> (Leaf2) but not its position.
>
> Is there a way to to that correctly ?
> Cordially,
> Julien Flotté.
>
> _________________________________________________________________
> Gagnez des pc Windows Vista avec Live.com http://www.image-addict.fr/
>
>
> --~------------------------------------------------------------------
> 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>
> --~--
>


--~------------------------------------------------------------------
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>
--~--


_________________________________________________________________
Windows Live Spaces : créez votre blog à votre image ! http://www.windowslive.fr/spaces


--~------------------------------------------------------------------
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>
--~--

<Prev in Thread] Current Thread [Next in Thread>