I rarely use XLST and get confusing results when I try to count child nodes in a parent node.
Edit:
The XML is structured as follows:
<?xml version="1.0"?>
<Response>
<result>
<name>Someone</name>
**<rating>4.5</rating>**
<review>
<text>Some review.</text>
</review>
<review>
<text>Another review.</text>
</review>
</result>
<result>
<name>Another one</name>
**<rating>2</rating>**
<review>
<text>Blah, grieve, blah.</text>
</review>
<review>
<text>Blah, grrrrr, blah.</text>
</review>
<review>
<text>Blah, good grrrrr, blah.</text>
</review>
</result>
...
...
</Response>
The template (simplified) is as follows:
**<body>
<xsl:apply-templates/>
</body>**
<xsl:template match="Response/result">
<div class="item">
<div class="name">
<xsl:value-of select="name"/>
</div>
<xsl:if test="rating">
<span class="review-count">
**(<xsl:value-of select="count(review)"/>)**
</span>
</xsl:if>
</div>
</xsl:template>
I do not get the correct child node count from this approach. In addition to the count(review), I tried count(descendant::review) and several xPath variations. I know I'm missing something simple - but what?
ratingelements so yourcount()won't get executed. - Daniel Haleyxsl:for-each(which would change context) when simplifying your xsl template did you? - Daniel Haley**(2)**for the first result and**(3)**for the second result. - Daniel Haley