|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] finding position in list of 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 =====================================================
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








