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

finding position in list of siblings

Subject: finding position in list of siblings
From: "John C Cartwright" <John.C.Cartwright@xxxxxxxx>
Date: Fri, 09 Jul 2004 12:56:57 -0600
finding siblings
Hello All,

I'm trying to find the context node's position relative to a list of identically named nodes. For example, given the following XML:

<?xml version="1.0" encoding="UTF-8"?>
<FAMILY>
  <SISTER/>
  <SISTER/>
  <BROTHER/>
  <BROTHER/>
  <BROTHER/>
</FAMILY>

I would like the 3 BROTHER nodes to show their position as 1,2,3 respectively rather than 3,4,5.

I've tried the following template, but can't seem to get the constraint right to eliminate from the node list all but the <BROTHER> elements. Can someone show me the way to do this?


<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text"/>
<xsl:strip-space elements="*"/>


<xsl:template match="/">
  <xsl:apply-templates select="/FAMILY/BROTHER" />
</xsl:template>

<xsl:template match="BROTHER">
   <xsl:value-of select="count(BROTHER/preceding-sibling::*)" />
   <xsl:value-of select="count(preceding-sibling::node()[.='BROTHER'])" />

</xsl:template>
</xsl:stylesheet>


Thanks!




-- john

=====================================================
John Cartwright
Associate Scientist
Geospatial Data Services Group
CIRES, National Geophysical Data Center/NOAA
(303) 497-6284
John.C.Cartwright@xxxxxxxx
=====================================================

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.