[xsl] finding position in list of siblings

Subject: [xsl] finding position in list of siblings
From: "John C Cartwright" <John.C.Cartwright@xxxxxxxx>
Date: Fri, 09 Jul 2004 12:56:57 -0600
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"?>

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



-- john

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

Current Thread