File: count.xsl

package info (click to toggle)
tclxml 3.3~svn11-2
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 4,392 kB
  • sloc: ansic: 13,292; tcl: 11,656; xml: 3,269; sh: 559; makefile: 15
file content (32 lines) | stat: -rw-r--r-- 897 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<xsl:stylesheet version='1.0'
  xmlns:xsl='http://www.w3.org/1999/XSL/Transform'>

  <xsl:template match='/'>
    <xsl:text>The document contains </xsl:text>
    <xsl:call-template name='add'>
      <xsl:with-param name='nodes' select='//text()'/>
    </xsl:call-template>
    <xsl:text> characters.
</xsl:text>
  </xsl:template>

  <xsl:template name='add'>
    <xsl:param name='sum' select='0'/>
    <xsl:param name='nodes' select='/..'/>

    <xsl:choose>
      <xsl:when test='not($nodes)'>
        <xsl:value-of select='$sum'/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:call-template name='add'>
          <xsl:with-param name='sum'
            select='$sum + string-length($nodes[1])'/>
          <xsl:with-param name='nodes'
            select='$nodes[position() != 1]'/>
        </xsl:call-template>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

</xsl:stylesheet>