xslt count sibling

envoy

New Member
i have a sample\[code\]<Root> <A rename="yes,it is option 1"/> <C rename="no"/> <A rename="yes,it is option 2"/> <C rename="no"/> <C rename="yes"/> <C rename="no"/> <A rename="yes,it is option 3"/> <A rename="yes,it is option 4"/> <C rename="no"/> <C rename="yes"/> <C rename="no"/> <C rename="no"/> </Root>\[/code\]then i apply a template look like this\[code\] <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output omit-xml-declaration="yes" indent="yes"/> <xsl:template match="A"> <p><b>option1: <xsl:value-of select="count(following-sibling::C[preceding-sibling::A[1]/@rename[contains(.,'option 1')]])"/></b></p> <p><b>option2: <xsl:value-of select="count(following-sibling::C[preceding-sibling::A[1]/@rename[contains(.,'option 2')]])"/></b></p> <p><b>option3: <xsl:value-of select="count(following-sibling::C[preceding-sibling::A[1]/@rename[contains(.,'option 3')]])"/></b></p> <p><b>option4: <xsl:value-of select="count(following-sibling::C[preceding-sibling::A[1]/@rename[contains(.,'option 4')]])"/></b></p> </xsl:template></xsl:stylesheet>\[/code\]but i want the output look like this,if there are not sibling following A, we just ignore this one.just print these @rename contains "option" and also contains elements\[code\]option1: 1 option2: 3 option4: 4 \[/code\]what i get now is\[code\]option1: 1 option2: 3 option3: 0 option4: 4 option1: 0 option2: 3 option3: 0 option4: 4 option1: 0 option2: 0 option3: 0 option4: 4 option1: 0 option2: 0 option3: 0 option4: 4 \[/code\]
 
Back
Top