[XSL-LIST Mailing List Archive Home]
[By Thread]
[By Date]
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:
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="*"/>
Thanks!
-- john
[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"?> <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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Using xsl:for-each-group , Jeni Tennison | Thread | Re: [xsl] finding position in list , Wendell Piez |
Re: [xsl] Figuring out for-group-by, Barry Lay | Date | RE: [xsl] finding position in list , cknell |
Month |