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

Re: Position of a Child

Subject: Re: Position of a Child
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Thu, 20 Sep 2001 14:58:24 -0400
xsl position child
Frank,

What you mean by "position of that child inside the context node" is actually a bit problematic, possibly meaning any of a number of things. How to get it depends both on what you mean, and what your input data looks like.

For starters, you could try (count(*[name()=$NodeName]/preceding-sibling::*) + 1) -- that is, 1 + the number of the node's preceding element siblings. If you have mixed content (and thus the siblings you want to count include text nodes), or if there's some other wrinkle (such as more than one child node being named $NodeName), come back.

position() isn't very useful because it returns the position of the context node within the current node list, which isn't what you want. You could make it be what you want by doing something like:

<xsl:for-each select="*">
  <xsl:if test="name()=$NodeName">
    <xsl:value-of select="."/>
    <xsl:value-of select="position()"/>
  </xsl:if>
</xsl:for-each>

But again, I'm making assumptions about what you really want -- and you can see this is more roundabout than simple counting the preceding siblings.

Cheers,
Wendell


At 02:17 PM 9/20/01, you wrote:
I'm having problems getting the child's position() of the context node.
I reference the child by its name (stored in a variable), like this:

<xsl:value-of select="*[name()=$NodeName]"/>

What I would like to get is the position of that child inside the context
node.


======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


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.