]> matita.cs.unibo.it Git - helm.git/blob - helm/style/mk_dep_graph.xsl
mk_dep_graph reimplemented using the forward-pointers metadata.
[helm.git] / helm / style / mk_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="0.1"
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="base_RDF_URI" select="'helm:rdf:www.cs.unibo.it/helm/rdf/forward//'"/>
147  <xsl:variable name="before" select="substring-before($uri,'#xpointer(1/')"/>
148  <xsl:value-of select="$base_RDF_URI"/>
149  <xsl:choose>
150   <xsl:when test="$before=''">
151    <xsl:value-of select="$uri"/>
152   </xsl:when>
153   <xsl:otherwise>
154    <xsl:value-of select="concat($before,',')"/>
155    <xsl:variable name="after" select="substring-after($uri,'#xpointer(1/')"/>
156    <xsl:value-of select="translate(substring-before($after,')'),'/',',')"/>
157   </xsl:otherwise>
158  </xsl:choose>
159 </xsl:template>
160
161 <xsl:template match="/">
162  <!--
163  <xsl:text>strict digraph L0 { size = "83,83"; concentrate=true; node [style=filled, shape = box];&CSCbr;</xsl:text>
164  -->
165  <xsl:text>strict digraph L0 { size = "83,83"; node [style=filled, shape = box];&CSCbr;</xsl:text>
166  <xsl:variable name="quoted_CICURI">
167   <xsl:call-template name="quote_url">
168    <xsl:with-param name="s" select="$CICURI"/>
169   </xsl:call-template>
170  </xsl:variable>
171  <!-- The nonce is used to force the document reload -->
172  <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))"/>
173  <xsl:variable name="dummy1" select="document(concat($uri_set_queueURL,'add_if_not_in?uri=',$quoted_CICURI,'&amp;nonce=',generate-id(),'&amp;PID=',$PID))"/>
174  <xsl:apply-templates mode="loop" select="document(concat($uri_set_queueURL,'get_next?uri=',$quoted_CICURI,'&amp;nonce=',generate-id(),'&amp;PID=',$PID))"/>
175  <xsl:variable name="dummy2" select="document(concat($uri_set_queueURL,'reset_to_empty?PID=',$PID))"/>
176  <xsl:text>}</xsl:text>
177 </xsl:template>
178
179 <xsl:template mode="loop" match="empty"/>
180
181 <xsl:template mode="loop" match="uri|marked_uri">
182  <xsl:variable name="rdfuri">
183   <xsl:call-template name="RDFURI_of_CICURI">
184    <xsl:with-param name="uri" select="@value"/>
185   </xsl:call-template>
186  </xsl:variable>
187  <xsl:variable name="document" select="document(concat($base_URL_of_URI,$rdfuri))"/>
188  <xsl:choose>
189   <xsl:when test="$document/*">
190    <xsl:apply-templates mode="first_time" select="$document/*">
191     <xsl:with-param name="currentCICURI" select="@value"/>
192     <xsl:with-param name="quotedCurrentCICURI">
193      <xsl:call-template name="quote">
194       <xsl:with-param name="s" select="@value"/>
195      </xsl:call-template>
196     </xsl:with-param>
197     <xsl:with-param name="do_not_visit" select="name(.)"/>
198    </xsl:apply-templates>
199   </xsl:when>
200   <xsl:otherwise>
201    <xsl:apply-templates mode="first_time" select=".">
202     <xsl:with-param name="currentCICURI" select="@value"/>
203     <xsl:with-param name="quotedCurrentCICURI">
204      <xsl:call-template name="quote">
205       <xsl:with-param name="s" select="@value"/>
206      </xsl:call-template>
207     </xsl:with-param>
208     <xsl:with-param name="do_not_visit" select="'no_deps'"/>
209    </xsl:apply-templates>
210   </xsl:otherwise>
211  </xsl:choose>
212  <xsl:variable name="quoted_value">
213   <xsl:call-template name="quote_url">
214    <xsl:with-param name="s" select="@value"/>
215   </xsl:call-template>
216  </xsl:variable>
217  <!-- The couple (uri,nonce) is used to force the document reload -->
218  <xsl:apply-templates mode="loop" select="document(concat($uri_set_queueURL,'get_next?uri=',$quoted_value,'&amp;nonce=',generate-id(),'&amp;PID=',$PID))"/>
219 </xsl:template>
220
221
222 <xsl:template mode="first_time" match="*">
223  <xsl:param name="currentCICURI" select="''"/>
224  <xsl:param name="quotedCurrentCICURI" select="''"/>
225  <xsl:param name="do_not_visit" select="'uri'"/>
226  <xsl:if test="$do_not_visit='uri'">
227   <xsl:apply-templates select=".">
228    <xsl:with-param name="currentCICURI" select="$currentCICURI"/>
229    <xsl:with-param name="quotedCurrentCICURI" select="$quotedCurrentCICURI"/>
230   </xsl:apply-templates>
231  </xsl:if>
232  <xsl:text> </xsl:text>
233  <xsl:value-of select="$quotedCurrentCICURI"/>
234 <!-- <xsl:text> [fontname="LucidaSansRegular",color=red,label="</xsl:text> -->
235  <xsl:text> [label="</xsl:text>
236  <xsl:value-of select="$currentCICURI"/>
237  <xsl:text>",URL="</xsl:text>
238  <xsl:value-of select="$currentCICURI"/>
239  <xsl:text>"</xsl:text>
240  <xsl:if test="name(document(concat($uri_set_queueURL,'is_overflowed?uri=',$quotedCurrentCICURI,'&amp;nonce=',generate-id(),'&amp;PID=',$PID))/*)='true'">
241   <xsl:text>,color=red</xsl:text>
242  </xsl:if>
243  <xsl:text>];&CSCbr;</xsl:text>
244 </xsl:template>
245
246 <xsl:template match="*">
247  <xsl:param name="currentCICURI" select="''"/>
248  <xsl:param name="quotedCurrentCICURI" select="''"/>
249  <xsl:for-each select="*/*/*">
250   <xsl:variable name="quotedURI">
251    <xsl:call-template name="quote">
252     <xsl:with-param name="s" select="@rdf:value"/>
253    </xsl:call-template>
254   </xsl:variable>
255   <xsl:variable name="quoted_uri">
256    <xsl:call-template name="quote_url">
257     <xsl:with-param name="s" select="@rdf:value"/>
258    </xsl:call-template>
259   </xsl:variable>
260   <!-- The nonce, quotedCurrentCICURI are used to force the document reload -->
261   <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')">
262    <xsl:text> </xsl:text>
263    <xsl:value-of select="$quotedCurrentCICURI"/>
264    <xsl:text> -&gt; </xsl:text>
265    <xsl:value-of select="$quotedURI"/>
266    <xsl:text>;&CSCbr;</xsl:text>
267   </xsl:if>
268  </xsl:for-each>
269 </xsl:template>
270
271 </xsl:stylesheet>