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

RE: Re: Is it possible to know position of ancestor?

Subject: RE: Re: Is it possible to know position of ancestor?
From: "Dion Houston" <dionh@xxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 17 Oct 2002 14:30:48 -0700
xslt position of ancestor
Here's another way to do it, and this works regardless of the namespace:

         <xsl:for-each select="..">
            <xsl:number/>
         </xsl:for-each>

Here's how it works:

<xsl:for-each> iterates through each of the nodes in the selected
nodeset.  In this case, that nodeset contains only one node, the parent.
<xsl:number> by default returns the sequence number of the current node
within the context of like named nodes at the same level.  

HTH!

Dion
-----Original Message-----
From: James Carlyle [mailto:james.carlyle@xxxxxxxxxxxx] 
Sent: Thursday, October 17, 2002 1:28 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: RE:  Re: Is it possible to know position of ancestor?

If you are not using namespaces, this will work

count(parent::*/preceding-sibling::*[name() =
name(current()/parent::*)]) +
1

Kind regards,

James Carlyle


> -----Original Message-----
> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of
> evgeniy.strokin@xxxxxxxxxxxxxxxx
> Sent: 17 October 2002 21:02
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject:  Re: Is it possible to know position of ancestor?
>
>
> But if you don't know name of element "line"? It should be the same
name
> only this you know.
>
> Thanks,
> Jenya
>
> James Carlyle writes:
>
> > Try
> >
> > select="count(../preceding-sibing::line + 1)"
> >
> > Kind regards,
> >
> > James Carlyle
> >
> >> -----Original Message-----
> >> From: owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> >> [mailto:owner-xsl-list@xxxxxxxxxxxxxxxxxxxxxx]On Behalf Of
> >> evgeniy.strokin@xxxxxxxxxxxxxxxx
> >> Sent: 17 October 2002 20:11
> >> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> >> Subject:  Re: Is it possible to know position of ancestor?
> >>
> >>
> >> Yes, you are so right (how do you know what I meant if I didn't
> >> know!?!? :)
> >> But here is also the problem:
> >> Let say we have another XML:
> >> <root>
> >>  <some_tag/>
> >>  <line>
> >>    <a/>
> >>    <b/>
> >>  </line>
> >>  <line>
> >>    <a/>
> >>    <b/> - we are here
> >>  </line>
> >> <root>
> >>
> >> In your example select="count(../preceding-sibing::* + 1)" we get
> >> 3 because
> >> it will count "some_tag" too. But we need to count only "line"
> elements.
> >> How we can solve this problem?
> >>
> >> Jenya
> >>
> >>
> >> David Carlisle writes:
> >>
> >> >
> >> >> We are in tag "b",
> >> > note that xslt works on elements (element nodes) not tags,
> and importat
> >> > distinction.
> >> >
> >> >>  We want to find out what is position of our ancestor
> >> >> in their ancestor.
> >> >
> >> > I think you mean parent rather than ancestor:
> >> >
> >> >  select="count(../preceding-sibing::* + 1)"
> >> >
> >> >
> >> > David
> >>
> >>
> >>  XSL-List info and archive:
http://www.mulberrytech.com/xsl/xsl-list
> >>
> >
> >  XSL-List info and archive:
http://www.mulberrytech.com/xsl/xsl-list
> >
>
>
>  XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
>


 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.