<xsl:param name="nosibling" select="0"/>
<xsl:choose>
<xsl:when test="count(child::*) = 0">
- <xsl:value-of select="$incurrent_length"/>
+ <!-- tremendous bug fixed. An empty element can still have siblings!!! -->
+ <xsl:variable name="siblength"><xsl:apply-templates select="following-sibling::*[position()=1]" mode="charcount"><xsl:with-param name="incurrent_length" select="$incurrent_length"/></xsl:apply-templates></xsl:variable>
+ <xsl:choose>
+ <xsl:when test="string($siblength) = """>
+ <xsl:value-of select="$incurrent_length"/>
+ </xsl:when>
+ <xsl:otherwise>
+ <xsl:value-of select="number($siblength)"/>
+ </xsl:otherwise>
+ </xsl:choose>
</xsl:when>
<xsl:otherwise>
<xsl:variable name="childlength"><xsl:apply-templates select="*[position()=1]" mode="charcount"><xsl:with-param name="incurrent_length" select="$incurrent_length"/><xsl:with-param name="nosibling" select="0"/></xsl:apply-templates></xsl:variable>