]> matita.cs.unibo.it Git - helm.git/blobdiff - helm/papers/use_case/stats/stats.xsl
* added .cc program (and equivalent .xsl stylesheet) for collecting
[helm.git] / helm / papers / use_case / stats / stats.xsl
diff --git a/helm/papers/use_case/stats/stats.xsl b/helm/papers/use_case/stats/stats.xsl
new file mode 100644 (file)
index 0000000..ea643f0
--- /dev/null
@@ -0,0 +1,130 @@
+<?xml version="1.0"?>
+
+<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
+
+<xsl:param name="URI" select="''"/>
+
+<xsl:output method="xml"/>
+
+<xsl:template match="/">
+<stats for="{$URI}">
+  <xsl:message>Computing max depth...</xsl:message>
+  <max-depth>
+    <xsl:call-template name="max-depth2"/>
+  </max-depth>
+  <xsl:message>Computing number of nodes...</xsl:message>
+  <number-of-elements>
+    <xsl:call-template name="number-of-elements"/>
+  </number-of-elements>
+  <number-of-text-nodes>
+    <xsl:call-template name="number-of-text-nodes"/>
+  </number-of-text-nodes>
+  <number-of-blank-text-nodes>
+    <xsl:call-template name="number-of-blank-text-nodes"/>
+  </number-of-blank-text-nodes>
+  <xsl:message>Computing number of leaves...</xsl:message>
+  <number-of-leaves>
+    <xsl:call-template name="number-of-leaves"/>
+  </number-of-leaves>
+</stats>
+</xsl:template>
+
+<xsl:template name="number-of-elements">
+  <xsl:value-of select="count(//*)"/>
+</xsl:template>
+
+<xsl:template name="number-of-text-nodes">
+  <xsl:value-of select="count(//text())"/>
+</xsl:template>
+
+<xsl:template name="number-of-blank-text-nodes">
+  <xsl:value-of select="count(//text()[normalize-space(.) = ''])"/>
+</xsl:template>
+
+<xsl:template name="number-of-leaves">
+  <xsl:value-of select="count(//text()|//*[not(child::node())])"/>
+</xsl:template>
+
+<xsl:template name="max-depth-aux">
+  <xsl:param name="nodes" select="/.."/>
+  <xsl:param name="depth" select="0"/>
+  <xsl:param name="DEPTH" select="0"/>
+  <xsl:choose>
+    <xsl:when test="$nodes">
+      <xsl:variable name="head-depth">
+        <xsl:call-template name="max-depth-aux">
+         <xsl:with-param name="nodes" select="$nodes[1]/*"/>
+         <xsl:with-param name="depth" select="$depth + 1"/>
+         <xsl:with-param name="DEPTH" select="$DEPTH"/>
+       </xsl:call-template>
+      </xsl:variable>
+      <xsl:variable name="NEW_DEPTH">
+        <xsl:choose>
+         <xsl:when test="$head-depth &gt; $DEPTH">
+           <xsl:value-of select="$head-depth"/>
+         </xsl:when>
+         <xsl:otherwise>
+           <xsl:value-of select="$DEPTH"/>
+         </xsl:otherwise>
+       </xsl:choose>
+      </xsl:variable>
+      <xsl:call-template name="max-depth-aux">
+        <xsl:with-param name="nodes" select="$nodes[position() &gt; 1]"/>
+        <xsl:with-param name="depth" select="$depth"/>
+       <xsl:with-param name="DEPTH" select="$NEW_DEPTH"/>
+      </xsl:call-template>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:choose>
+        <xsl:when test="$depth &gt; $DEPTH">
+         <xsl:value-of select="$depth"/>
+       </xsl:when>
+       <xsl:otherwise>
+          <xsl:value-of select="$DEPTH"/>
+       </xsl:otherwise>
+      </xsl:choose>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template name="max-depth">
+  <xsl:call-template name="max-depth-aux">
+    <xsl:with-param name="nodes" select="//node()"/>
+  </xsl:call-template>
+</xsl:template>
+
+<xsl:template name="max-depth2-aux">
+  <xsl:param name="nodes" select="/.."/>
+  <xsl:param name="DEPTH" select="0"/>
+  <xsl:choose>
+    <xsl:when test="$nodes">
+      <xsl:variable name="depth" select="count($nodes[1]/ancestor::*)"/>
+      <xsl:variable name="NEW_DEPTH">
+        <xsl:choose>
+          <xsl:when test="$depth &gt; $DEPTH">
+           <xsl:value-of select="$depth"/>
+         </xsl:when>
+         <xsl:otherwise>
+           <xsl:value-of select="$DEPTH"/>
+         </xsl:otherwise>
+        </xsl:choose>
+      </xsl:variable>
+      <xsl:call-template name="max-depth2-aux">
+        <xsl:with-param name="nodes" select="$nodes[position() &gt; 1]"/>
+       <xsl:with-param name="DEPTH" select="$NEW_DEPTH"/>
+      </xsl:call-template>
+    </xsl:when>
+    <xsl:otherwise>
+      <xsl:value-of select="$DEPTH"/>
+    </xsl:otherwise>
+  </xsl:choose>
+</xsl:template>
+
+<xsl:template name="max-depth2">
+  <xsl:call-template name="max-depth2-aux">
+    <xsl:with-param name="nodes" select="//node()[not(child::node())]"/>
+  </xsl:call-template>
+</xsl:template>
+
+</xsl:stylesheet>
+