]> matita.cs.unibo.it Git - helm.git/blob - helm/style/mk_meta_and_dep_graph.xsl
- the mathql interpreter is not helm-dependent any more
[helm.git] / helm / style / mk_meta_and_dep_graph.xsl
1 <?xml version="1.0"?>
2
3 <!-- Copyright (C) 2000, HELM Team                                     -->
4 <!--                                                                   -->
5 <!-- This file is part of HELM, an Hypertextual, Electronic            -->
6 <!-- Library of Mathematics, developed at the Computer Science         -->
7 <!-- Department, University of Bologna, Italy.                         -->
8 <!--                                                                   -->
9 <!-- HELM is free software; you can redistribute it and/or             -->
10 <!-- modify it under the terms of the GNU General Public License       -->
11 <!-- as published by the Free Software Foundation; either version 2    -->
12 <!-- of the License, or (at your option) any later version.            -->
13 <!--                                                                   -->
14 <!-- HELM is distributed in the hope that it will be useful,           -->
15 <!-- but WITHOUT ANY WARRANTY; without even the implied warranty of    -->
16 <!-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the     -->
17 <!-- GNU General Public License for more details.                      -->
18 <!--                                                                   -->
19 <!-- You should have received a copy of the GNU General Public License -->
20 <!-- along with HELM; if not, write to the Free Software               -->
21 <!-- Foundation, Inc., 59 Temple Place - Suite 330, Boston,            -->
22 <!-- MA  02111-1307, USA.                                              -->
23 <!--                                                                   -->
24 <!-- For details, see the HELM World-Wide-Web page,                    -->
25 <!-- http://cs.unibo.it/helm/.                                         -->
26
27 <!-- CSC: Sostituire l'andata a capo con la entity numerica opportuna -->
28 <!DOCTYPE html [
29  <!ENTITY CSCbr "
30 ">
31 ]>
32
33 <xsl:stylesheet version="1.0"
34   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
35   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
36   xmlns:h="http:/www.cs.unibo.it/helm/schemas/schema-h.rdf#">
37
38 <xsl:output method="text"/>
39
40 <xsl:param name="CICURI" select="''"/>
41 <xsl:param name="PID" select="''"/>
42 <xsl:param name="getterURL" select="''"/>
43 <xsl:param name="uri_set_queueURL" select="''"/>
44 <xsl:param name="uri_set_size" select="30"/>
45 <xsl:variable name="base_URL_of_URI" select="concat($getterURL,'getxml?uri=')"/>
46
47 <!-- CSC: next functions because I don't remember the name of the    -->
48 <!-- CSC: subst function of xslt and I don't have the specs with me -->
49
50 <!-- The next function is used to quote URIs for dotty -->
51 <xsl:template name="quote">
52  <xsl:param name="s" select="''"/>
53  <xsl:param name="news" select="''"/>
54  <xsl:choose>
55   <xsl:when test="$s = ''"><xsl:value-of select="$news"/></xsl:when>
56   <xsl:otherwise>
57    <xsl:variable name="char" select="substring($s,1,1)"/>
58    <xsl:choose>
59     <xsl:when test="$char = '/'">
60      <xsl:call-template name="quote">
61       <xsl:with-param name="s" select="substring($s,2)"/>
62       <xsl:with-param name="news" select="concat($news,'X')"/>
63      </xsl:call-template>
64     </xsl:when>
65     <xsl:when test="$char = ':'">
66      <xsl:call-template name="quote">
67       <xsl:with-param name="s" select="substring($s,2)"/>
68       <xsl:with-param name="news" select="concat($news,'Y')"/>
69      </xsl:call-template>
70     </xsl:when>
71     <xsl:when test="$char = '.'">
72      <xsl:call-template name="quote">
73       <xsl:with-param name="s" select="substring($s,2)"/>
74       <xsl:with-param name="news" select="concat($news,'Z')"/>
75      </xsl:call-template>
76     </xsl:when>
77     <xsl:when test='$char = "&apos;"'>
78      <xsl:call-template name="quote">
79       <xsl:with-param name="s" select="substring($s,2)"/>
80       <xsl:with-param name="news" select="concat($news,'W')"/>
81      </xsl:call-template>
82     </xsl:when>
83     <xsl:when test="$char = '-'">
84      <xsl:call-template name="quote">
85       <xsl:with-param name="s" select="substring($s,2)"/>
86       <xsl:with-param name="news" select="concat($news,'J')"/>
87      </xsl:call-template>
88     </xsl:when>
89     <xsl:when test="$char = '#'">
90      <xsl:call-template name="quote">
91       <xsl:with-param name="s" select="substring($s,2)"/>
92       <xsl:with-param name="news" select="concat($news,'G')"/>
93      </xsl:call-template>
94     </xsl:when>
95     <xsl:when test="$char = '('">
96      <xsl:call-template name="quote">
97       <xsl:with-param name="s" select="substring($s,2)"/>
98       <xsl:with-param name="news" select="concat($news,'O')"/>
99      </xsl:call-template>
100     </xsl:when>
101     <xsl:when test="$char = ')'">
102      <xsl:call-template name="quote">
103       <xsl:with-param name="s" select="substring($s,2)"/>
104       <xsl:with-param name="news" select="concat($news,'C')"/>
105      </xsl:call-template>
106     </xsl:when>
107     <xsl:otherwise>
108      <xsl:call-template name="quote">
109       <xsl:with-param name="s" select="substring($s,2)"/>
110       <xsl:with-param name="news" select="concat($news,$char)"/>
111      </xsl:call-template>
112     </xsl:otherwise>
113    </xsl:choose>
114   </xsl:otherwise>
115  </xsl:choose>
116 </xsl:template>
117
118 <!-- The next function is used to quote URIs to embed them in an URL -->
119 <xsl:template name="quote_url">
120  <xsl:param name="s" select="''"/>
121  <xsl:param name="news" select="''"/>
122  <xsl:choose>
123   <xsl:when test="$s = ''"><xsl:value-of select="$news"/></xsl:when>
124   <xsl:otherwise>
125    <xsl:variable name="char" select="substring($s,1,1)"/>
126    <xsl:choose>
127     <xsl:when test="$char = '#'">
128      <xsl:call-template name="quote_url">
129       <xsl:with-param name="s" select="substring($s,2)"/>
130       <xsl:with-param name="news" select="concat($news,'%23')"/>
131      </xsl:call-template>
132     </xsl:when>
133     <xsl:otherwise>
134      <xsl:call-template name="quote_url">
135       <xsl:with-param name="s" select="substring($s,2)"/>
136       <xsl:with-param name="news" select="concat($news,$char)"/>
137      </xsl:call-template>
138     </xsl:otherwise>
139    </xsl:choose>
140   </xsl:otherwise>
141  </xsl:choose>
142 </xsl:template>
143
144 <xsl:template name="RDFURI_of_CICURI">
145  <xsl:param name="uri" select="''"/>
146  <xsl:variable name="before" select="substring-before($uri,'#xpointer(1/')"/>
147  <xsl:value-of select="$base_RDF_URI"/>
148  <xsl:choose>
149   <xsl:when test="$before=''">
150    <xsl:value-of select="$uri"/>
151   </xsl:when>
152   <xsl:otherwise>
153    <xsl:value-of select="concat($before,',')"/>
154    <xsl:variable name="after" select="substring-after($uri,'#xpointer(1/')"/>
155    <xsl:value-of select="translate(substring-before($after,')'),'/',',')"/>
156   </xsl:otherwise>
157  </xsl:choose>
158 </xsl:template>
159
160 <xsl:template match="/">
161  <!--
162  <xsl:text>strict digraph L0 { size = "83,83"; concentrate=true; node [style=filled, shape = box];&CSCbr;</xsl:text>
163  -->
164  <xsl:text>strict digraph L0 { size = "83,83"; node [style=filled, shape = box];&CSCbr;</xsl:text>
165  <xsl:variable name="quoted_CICURI">
166   <xsl:call-template name="quote_url">
167    <xsl:with-param name="s" select="$CICURI"/>
168   </xsl:call-template>
169  </xsl:variable>
170  <!-- The nonce is used to force the document reload -->
171  <xsl:variable name="dummy0" select="document(concat($uri_set_queueURL,'set_uri_set_size?uri=',$quoted_CICURI,'&amp;nonce=',generate-id(),'&amp;PID=',$PID,'&amp;size=',$uri_set_size))"/>
172  <xsl:variable name="dummy1" select="document(concat($uri_set_queueURL,'add_if_not_in?uri=',$quoted_CICURI,'&amp;nonce=',generate-id(),'&amp;PID=',$PID))"/>
173  <xsl:apply-templates mode="loop" select="document(concat($uri_set_queueURL,'get_next?uri=',$quoted_CICURI,'&amp;nonce=',generate-id(),'&amp;PID=',$PID))"/>
174  <xsl:variable name="dummy2" select="document(concat($uri_set_queueURL,'reset_to_empty?PID=',$PID))"/>
175  <xsl:text>}</xsl:text>
176 </xsl:template>
177
178 <xsl:template mode="loop" match="empty"/>
179
180 <xsl:template mode="loop" match="uri|marked_uri">
181  <xsl:variable name="rdfuri">
182   <xsl:call-template name="RDFURI_of_CICURI">
183    <xsl:with-param name="uri" select="@value"/>
184   </xsl:call-template>
185  </xsl:variable>
186  <xsl:variable name="document" select="document(concat($base_URL_of_URI,$rdfuri))"/>
187  <xsl:choose>
188   <xsl:when test="$document/*">
189    <xsl:apply-templates mode="first_time" select="$document/*">
190     <xsl:with-param name="currentCICURI" select="@value"/>
191     <xsl:with-param name="quotedCurrentCICURI">
192      <xsl:call-template name="quote">
193       <xsl:with-param name="s" select="@value"/>
194      </xsl:call-template>
195     </xsl:with-param>
196     <xsl:with-param name="do_not_visit" select="name(.)"/>
197    </xsl:apply-templates>
198   </xsl:when>
199   <xsl:otherwise>
200    <xsl:apply-templates mode="first_time" select=".">
201     <xsl:with-param name="currentCICURI" select="@value"/>
202     <xsl:with-param name="quotedCurrentCICURI">
203      <xsl:call-template name="quote">
204       <xsl:with-param name="s" select="@value"/>
205      </xsl:call-template>
206     </xsl:with-param>
207     <xsl:with-param name="do_not_visit" select="'no_deps'"/>
208    </xsl:apply-templates>
209   </xsl:otherwise>
210  </xsl:choose>
211  <xsl:variable name="quoted_value">
212   <xsl:call-template name="quote_url">
213    <xsl:with-param name="s" select="@value"/>
214   </xsl:call-template>
215  </xsl:variable>
216  <!-- The couple (uri,nonce) is used to force the document reload -->
217  <xsl:apply-templates mode="loop" select="document(concat($uri_set_queueURL,'get_next?uri=',$quoted_value,'&amp;nonce=',generate-id(),'&amp;PID=',$PID))"/>
218 </xsl:template>
219
220
221 <xsl:template mode="first_time" match="*">
222  <xsl:param name="currentCICURI" select="''"/>
223  <xsl:param name="quotedCurrentCICURI" select="''"/>
224  <xsl:param name="do_not_visit" select="'uri'"/>
225  <xsl:if test="$do_not_visit='uri'">
226   <xsl:apply-templates select=".">
227    <xsl:with-param name="currentCICURI" select="$currentCICURI"/>
228    <xsl:with-param name="quotedCurrentCICURI" select="$quotedCurrentCICURI"/>
229   </xsl:apply-templates>
230  </xsl:if>
231  <xsl:text> </xsl:text>
232  <xsl:value-of select="$quotedCurrentCICURI"/>
233 <!-- <xsl:text> [fontname="LucidaSansRegular",color=red,label="</xsl:text> -->
234  <xsl:text> [label="</xsl:text>
235  <xsl:value-of select="$currentCICURI"/>
236  <xsl:text>",URL="</xsl:text>
237  <xsl:value-of select="$currentCICURI"/>
238  <xsl:text>"</xsl:text>
239  <xsl:if test="name(document(concat($uri_set_queueURL,'is_overflowed?uri=',$quotedCurrentCICURI,'&amp;nonce=',generate-id(),'&amp;PID=',$PID))/*)='true'">
240   <xsl:text>,color=red</xsl:text>
241  </xsl:if>
242  <xsl:text>];&CSCbr;</xsl:text>
243 </xsl:template>
244
245 <xsl:template match="*">
246  <xsl:param name="currentCICURI" select="''"/>
247  <xsl:param name="quotedCurrentCICURI" select="''"/>
248  <xsl:for-each select="*/*/*">
249   <xsl:variable name="quotedURI">
250    <xsl:call-template name="quote">
251     <xsl:with-param name="s" select="@rdf:value"/>
252    </xsl:call-template>
253   </xsl:variable>
254   <xsl:variable name="quoted_uri">
255    <xsl:call-template name="quote_url">
256     <xsl:with-param name="s" select="@rdf:value"/>
257    </xsl:call-template>
258   </xsl:variable>
259   <!-- The nonce, quotedCurrentCICURI are used to force the document reload -->
260   <xsl:if test="not(name(document(concat($uri_set_queueURL,'add_if_not_in?uri=',$quoted_uri,'&amp;nonce=',generate-id(),'&amp;PID=',$PID,'&amp;quotedCurrentCICURI=',$quotedCurrentCICURI))/*)='not_added_because_already_too_many')">
261    <xsl:text> </xsl:text>
262    <xsl:value-of select="$quotedCurrentCICURI"/>
263    <xsl:text> -&gt; </xsl:text>
264    <xsl:value-of select="$quotedURI"/>
265    <xsl:value-of select="$link_direction"/>
266    <xsl:text>;&CSCbr;</xsl:text>
267   </xsl:if>
268  </xsl:for-each>
269 </xsl:template>
270
271 </xsl:stylesheet>