"sylvain.loiseau" <sy*************@wanadoo.fr> wrote in message news:<c1**********@news-reader5.wanadoo.fr>...
Hope this helped.
Yes it helped. Thanks !
Sylvain
Another way to do this is by using the Tree Visitor pattern:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="yes"/>
<xsl:strip-space elements="*"/>
<xsl:template match="@* | node()" name="treeVisitor">
<xsl:param name="ptxtLength" select="0"/>
<xsl:variable name="vsubtreeLength">
<xsl:choose>
<xsl:when test="not(node())">0</xsl:when>
<xsl:otherwise>
<xsl:apply-templates select="node()[1]">
<xsl:with-param name="ptxtLength"
select="$ptxtLength"/>
</xsl:apply-templates>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:choose>
<xsl:when test="following-sibling::node()">
<xsl:apply-templates select="following-sibling::node()[1]">
<xsl:with-param name="ptxtLength"
select="$ptxtLength + $vsubtreeLength * (number(.) = number(.))"/>
</xsl:apply-templates>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$vsubtreeLength"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template match="node()[not(node()) and not(following-sibling::node())]">
<xsl:param name="ptxtLength" select="0"/>
<xsl:value-of select="$ptxtLength"/>
</xsl:template>
<xsl:template match="person">
<xsl:param name="ptxtLength" select="0"/>
<xsl:call-template name="treeVisitor">
<xsl:with-param name="ptxtLength"
select="$ptxtLength + string-length(.)"/>
</xsl:call-template>
</xsl:template>
</xsl:stylesheet>
When this transformation is applied on this source.xml:
<persons>
<person name="pt" public="false">
<password>asdf</password>
</person>
<person name="ab" public="true">xx</person>
</persons>
the wanted result is obtained:
6
Cheers,
Dimitre Novatchev [XML MVP],
FXSL developer, XML Insider,
http://fxsl.sourceforge.net/ -- the home of FXSL
Resume:
http://fxsl.sf.net/DNovatchev/Resume/Res.html