3 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
5 <xsl:param name="URI" select="''"/>
7 <xsl:output method="xml"/>
9 <xsl:template match="/">
11 <xsl:message>Computing max depth...</xsl:message>
13 <xsl:call-template name="max-depth2"/>
15 <xsl:message>Computing number of nodes...</xsl:message>
17 <xsl:call-template name="number-of-elements"/>
19 <number-of-text-nodes>
20 <xsl:call-template name="number-of-text-nodes"/>
21 </number-of-text-nodes>
22 <number-of-blank-text-nodes>
23 <xsl:call-template name="number-of-blank-text-nodes"/>
24 </number-of-blank-text-nodes>
25 <xsl:message>Computing number of leaves...</xsl:message>
27 <xsl:call-template name="number-of-leaves"/>
32 <xsl:template name="number-of-elements">
33 <xsl:value-of select="count(//*)"/>
36 <xsl:template name="number-of-text-nodes">
37 <xsl:value-of select="count(//text())"/>
40 <xsl:template name="number-of-blank-text-nodes">
41 <xsl:value-of select="count(//text()[normalize-space(.) = ''])"/>
44 <xsl:template name="number-of-leaves">
45 <xsl:value-of select="count(//text()|//*[not(child::node())])"/>
48 <xsl:template name="max-depth-aux">
49 <xsl:param name="nodes" select="/.."/>
50 <xsl:param name="depth" select="0"/>
51 <xsl:param name="DEPTH" select="0"/>
53 <xsl:when test="$nodes">
54 <xsl:variable name="head-depth">
55 <xsl:call-template name="max-depth-aux">
56 <xsl:with-param name="nodes" select="$nodes[1]/*"/>
57 <xsl:with-param name="depth" select="$depth + 1"/>
58 <xsl:with-param name="DEPTH" select="$DEPTH"/>
61 <xsl:variable name="NEW_DEPTH">
63 <xsl:when test="$head-depth > $DEPTH">
64 <xsl:value-of select="$head-depth"/>
67 <xsl:value-of select="$DEPTH"/>
71 <xsl:call-template name="max-depth-aux">
72 <xsl:with-param name="nodes" select="$nodes[position() > 1]"/>
73 <xsl:with-param name="depth" select="$depth"/>
74 <xsl:with-param name="DEPTH" select="$NEW_DEPTH"/>
79 <xsl:when test="$depth > $DEPTH">
80 <xsl:value-of select="$depth"/>
83 <xsl:value-of select="$DEPTH"/>
90 <xsl:template name="max-depth">
91 <xsl:call-template name="max-depth-aux">
92 <xsl:with-param name="nodes" select="//node()"/>
96 <xsl:template name="max-depth2-aux">
97 <xsl:param name="nodes" select="/.."/>
98 <xsl:param name="DEPTH" select="0"/>
100 <xsl:when test="$nodes">
101 <xsl:variable name="depth" select="count($nodes[1]/ancestor::*)"/>
102 <xsl:variable name="NEW_DEPTH">
104 <xsl:when test="$depth > $DEPTH">
105 <xsl:value-of select="$depth"/>
108 <xsl:value-of select="$DEPTH"/>
112 <xsl:call-template name="max-depth2-aux">
113 <xsl:with-param name="nodes" select="$nodes[position() > 1]"/>
114 <xsl:with-param name="DEPTH" select="$NEW_DEPTH"/>
118 <xsl:value-of select="$DEPTH"/>
123 <xsl:template name="max-depth2">
124 <xsl:call-template name="max-depth2-aux">
125 <xsl:with-param name="nodes" select="//node()[not(child::node())]"/>