Counting previous Attributes with a specific value in XSLT

mrgmc

New Member
I apologize ahead of time if this isn't properly formatted, but...I need to take the following xml:\[code\]<box r="?" c="?" b="?"> <h r="?" b="2"> <u> <v c="5" b="2"> <l> <h r="?" b="1"/> </l> <r> <v c="?" b="?"/> </r> </v> </u> <d> <h r="?" b="2"/> </d> </h></box>\[/code\]and using xslt:\[code\]<xsl:template name="BoxVariables-Count"> <xsl:text> // Counting...</xsl:text> <xsl:apply-templates select="descendant::*[@* = "?"]" mode="box-variable-count"/></xsl:template><xsl:template match="local:*" mode="box-variable-count"> <xsl:variable name="position" select="position()"/> <xsl:text> // </xsl:text></xsl:text><xsl:value-of select="local-name()"/> <xsl:text> = </xsl:text> <xsl:value-of select="count((ancestor::local:box[1]/descendant-or-self::*[@* = "?"][position() < $position + 1])/@*[@* = "?"])"/></xsl:template>\[/code\]count the number of "?" attribute entries that occur before the current node in the box element. (As a note: the "?" is actually "Unknown")The following line outputs the total number of attributes within nodes containing "?"s before the current node:\[code\]<xsl:value-of select="count((ancestor::local:box[1]/descendant-or-self::*[@* = "?"][position() < $position + 1])/@*)"/>\[/code\]outputs:\[code\] // h = 3 // h = 5 // v = 7 // h = 9\[/code\]BUT, I want to only count the number of "?" attributes within that set.\[code\]<xsl:value-of select="count((ancestor::local:box[1]/descendant-or-self::*[@* = "?"][position() < $position + 1])/@*[@* = "?"])"/>\[/code\]outputs:\[code\] // h = 0 // h = 0 // v = 0 // h = 0\[/code\]and I want:\[code\] // h = 3 // h = 4 // v = 5 // h = 7\[/code\]In other words:\[code\]count(./@*[@* = "?"])\[/code\]seems to return 0 and not the number of attributes within self that are set to "?".It would be nice if I didn't have to write a recursive ? counter...
 
Top