]> matita.cs.unibo.it Git - helm.git/blob - helm/nuprl_stylesheets/nuprl_expand.xsl
paths trough terms implemented with a nice hack :)
[helm.git] / helm / nuprl_stylesheets / nuprl_expand.xsl
1 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
2                               xmlns:m="http://www.w3.org/1998/Math/MathML"
3                               xmlns:xlink="http://www.w3.org/1999/xlink">
4
5 <xsl:key name="sequent" use="m:mtr/m:mtd/m:mrow/m:mtext/text()" match="m:mtable[starts-with(m:mtr/m:mtd/m:mrow/m:mtext/text(),'Sequent (')]"/>
6
7 <xsl:template match="/">
8     <xsl:apply-templates select="*"/>
9 </xsl:template>
10
11 <xsl:template match="m:mi">
12  <xsl:param name="sequentno" select="'/..'"/>
13     <xsl:choose>
14     <xsl:when test="contains(.,'%')">
15     <xsl:variable name="var" select="."/>
16      <m:maction actiontype="toggle">
17       <m:mi mathcolor="green"><xsl:value-of select="."/></m:mi>
18       <m:mrow>
19        <m:mi mathcolor="green"><xsl:value-of select="$var"/>: </m:mi>
20        <xsl:call-template name="look_for_decl">
21         <xsl:with-param name="csequent" select="$sequentno"/>
22         <xsl:with-param name="var" select="$var"/>
23        </xsl:call-template>
24       </m:mrow>
25      </m:maction>
26     </xsl:when>
27     <xsl:otherwise>
28      <xsl:copy>
29       <xsl:apply-templates select="@*|node()"/>
30      </xsl:copy>
31     </xsl:otherwise>
32     </xsl:choose>
33 </xsl:template>
34
35 <xsl:template match="m:mtable[starts-with(m:mtr/m:mtd/m:mrow/m:mtext/text(),'Sequent')]">
36  <xsl:copy>
37   <xsl:variable name="text" select="m:mtr/m:mtd/m:mrow/m:mtext/text()"/>
38   <xsl:variable name="tmp1" select="substring-after($text,'Sequent (')"/>
39   <xsl:variable name="tmp2" select="substring-before($tmp1,')')"/>
40   <xsl:apply-templates select="*|@*|text()">
41    <xsl:with-param name="sequentno" select="$tmp2"/>
42   </xsl:apply-templates>
43  </xsl:copy>
44 </xsl:template>
45
46 <xsl:template match="*|@*|text()">
47  <xsl:param name="sequentno" select="'/..'"/> 
48  <xsl:copy>
49   <xsl:apply-templates select="*|@*|text()">
50    <xsl:with-param name="sequentno" select="$sequentno"/>
51   </xsl:apply-templates>
52  </xsl:copy>
53 </xsl:template>
54
55 <xsl:template name="look_for_decl">
56    <xsl:param name="csequent" select="/.."/>
57    <xsl:param name="var" select="''"/>
58    <xsl:param name="result" select="0"/>
59    <xsl:choose>
60    <xsl:when test="$csequent=''">
61         <m:mi>
62          ERROR
63         </m:mi>
64    </xsl:when>
65    <xsl:otherwise>
66     <xsl:variable name="sect_table" select="key('sequent',concat('Sequent (',$csequent,')'))"/>
67     <xsl:variable name="check_res" select="$sect_table/m:mtr/m:mtable/m:mtr/m:mtd/m:mrow/m:mo[text()=$var]/following-sibling::*[2]"/>
68      <xsl:choose>
69      <xsl:when test="not ($check_res)">
70       <xsl:variable name="new_sequent">
71        <xsl:call-template name="truncate">
72         <xsl:with-param name="tail" select="$csequent"/>
73        </xsl:call-template>
74       </xsl:variable>
75       <xsl:call-template name="look_for_decl">
76        <xsl:with-param name="csequent" select="$new_sequent"/>
77        <xsl:with-param name="var" select="$var"/>
78       </xsl:call-template>
79      </xsl:when>
80      <xsl:otherwise>
81       <xsl:copy-of select="$check_res"/>
82      </xsl:otherwise>
83      </xsl:choose>
84    </xsl:otherwise>
85    </xsl:choose>
86 </xsl:template>
87
88 <xsl:template name="truncate">
89  <xsl:param name="tail" select="''"/>
90  <xsl:param name="head" select="''"/>
91  <xsl:choose>
92  <xsl:when test="substring-before($tail,' ')=''">
93   <xsl:value-of select="$head"/>
94  </xsl:when>
95  <xsl:otherwise>
96   <xsl:variable name="head1">
97    <xsl:if test="$head !=''">
98     <xsl:value-of select="concat($head,' ')"/>
99    </xsl:if>
100   </xsl:variable>
101   <xsl:call-template name="truncate">
102    <xsl:with-param name="tail" select="substring-after($tail,' ')"/>
103    <xsl:with-param name="head" select="concat($head1,substring-before($tail,' '))"/>
104   </xsl:call-template>
105  </xsl:otherwise>
106  </xsl:choose>
107 </xsl:template>
108 </xsl:stylesheet>