]> matita.cs.unibo.it Git - helm.git/blob - helm/papers/use_case/stats/stats.xsl
ocaml 3.09 transition
[helm.git] / helm / papers / use_case / stats / stats.xsl
1 <?xml version="1.0"?>
2
3 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
4
5 <xsl:param name="URI" select="''"/>
6
7 <xsl:output method="xml"/>
8
9 <xsl:template match="/">
10 <stats for="{$URI}">
11   <xsl:message>Computing max depth...</xsl:message>
12   <max-depth>
13     <xsl:call-template name="max-depth2"/>
14   </max-depth>
15   <xsl:message>Computing number of nodes...</xsl:message>
16   <number-of-elements>
17     <xsl:call-template name="number-of-elements"/>
18   </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>
26   <number-of-leaves>
27     <xsl:call-template name="number-of-leaves"/>
28   </number-of-leaves>
29 </stats>
30 </xsl:template>
31
32 <xsl:template name="number-of-elements">
33   <xsl:value-of select="count(//*)"/>
34 </xsl:template>
35
36 <xsl:template name="number-of-text-nodes">
37   <xsl:value-of select="count(//text())"/>
38 </xsl:template>
39
40 <xsl:template name="number-of-blank-text-nodes">
41   <xsl:value-of select="count(//text()[normalize-space(.) = ''])"/>
42 </xsl:template>
43
44 <xsl:template name="number-of-leaves">
45   <xsl:value-of select="count(//text()|//*[not(child::node())])"/>
46 </xsl:template>
47
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"/>
52   <xsl:choose>
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"/>
59         </xsl:call-template>
60       </xsl:variable>
61       <xsl:variable name="NEW_DEPTH">
62         <xsl:choose>
63           <xsl:when test="$head-depth &gt; $DEPTH">
64             <xsl:value-of select="$head-depth"/>
65           </xsl:when>
66           <xsl:otherwise>
67             <xsl:value-of select="$DEPTH"/>
68           </xsl:otherwise>
69         </xsl:choose>
70       </xsl:variable>
71       <xsl:call-template name="max-depth-aux">
72         <xsl:with-param name="nodes" select="$nodes[position() &gt; 1]"/>
73         <xsl:with-param name="depth" select="$depth"/>
74         <xsl:with-param name="DEPTH" select="$NEW_DEPTH"/>
75       </xsl:call-template>
76     </xsl:when>
77     <xsl:otherwise>
78       <xsl:choose>
79         <xsl:when test="$depth &gt; $DEPTH">
80           <xsl:value-of select="$depth"/>
81         </xsl:when>
82         <xsl:otherwise>
83           <xsl:value-of select="$DEPTH"/>
84         </xsl:otherwise>
85       </xsl:choose>
86     </xsl:otherwise>
87   </xsl:choose>
88 </xsl:template>
89
90 <xsl:template name="max-depth">
91   <xsl:call-template name="max-depth-aux">
92     <xsl:with-param name="nodes" select="//node()"/>
93   </xsl:call-template>
94 </xsl:template>
95
96 <xsl:template name="max-depth2-aux">
97   <xsl:param name="nodes" select="/.."/>
98   <xsl:param name="DEPTH" select="0"/>
99   <xsl:choose>
100     <xsl:when test="$nodes">
101       <xsl:variable name="depth" select="count($nodes[1]/ancestor::*)"/>
102       <xsl:variable name="NEW_DEPTH">
103         <xsl:choose>
104           <xsl:when test="$depth &gt; $DEPTH">
105             <xsl:value-of select="$depth"/>
106           </xsl:when>
107           <xsl:otherwise>
108             <xsl:value-of select="$DEPTH"/>
109           </xsl:otherwise>
110         </xsl:choose>
111       </xsl:variable>
112       <xsl:call-template name="max-depth2-aux">
113         <xsl:with-param name="nodes" select="$nodes[position() &gt; 1]"/>
114         <xsl:with-param name="DEPTH" select="$NEW_DEPTH"/>
115       </xsl:call-template>
116     </xsl:when>
117     <xsl:otherwise>
118       <xsl:value-of select="$DEPTH"/>
119     </xsl:otherwise>
120   </xsl:choose>
121 </xsl:template>
122
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())]"/>
126   </xsl:call-template>
127 </xsl:template>
128
129 </xsl:stylesheet>
130