]> matita.cs.unibo.it Git - helm.git/blob - helm/style/mk_meta_and_dep_graph.xsl
added sort CProp
[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 <xsl:stylesheet version="1.0"
28   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
29   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
30   xmlns:h="http://www.cs.unibo.it/helm/schemas/mattone.rdf#">
31
32 <xsl:output method="text"/>
33
34 <xsl:param name="CICURI" select="''"/>
35 <xsl:param name="PID" select="''"/>
36 <xsl:param name="getterURL" select="''"/>
37 <xsl:param name="uri_set_queueURL" select="''"/>
38 <xsl:param name="uri_set_size" select="30"/>
39 <xsl:variable name="base_URL_of_URI" select="concat($getterURL,'getxml?uri=')"/>
40
41 <!-- CSC: next functions because I don't remember the name of the    -->
42 <!-- CSC: subst function of xslt and I don't have the specs with me -->
43
44 <!-- The next function is used to quote URIs for dotty -->
45 <xsl:template name="quote">
46  <xsl:param name="s" select="''"/>
47  <xsl:param name="news" select="''"/>
48  <xsl:choose>
49   <xsl:when test="$s = ''"><xsl:value-of select="$news"/></xsl:when>
50   <xsl:otherwise>
51    <xsl:variable name="char" select="substring($s,1,1)"/>
52    <xsl:choose>
53     <xsl:when test="$char = '/'">
54      <xsl:call-template name="quote">
55       <xsl:with-param name="s" select="substring($s,2)"/>
56       <xsl:with-param name="news" select="concat($news,'X')"/>
57      </xsl:call-template>
58     </xsl:when>
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,'Y')"/>
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,'Z')"/>
69      </xsl:call-template>
70     </xsl:when>
71     <xsl:when test='$char = "&apos;"'>
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,'W')"/>
75      </xsl:call-template>
76     </xsl:when>
77     <xsl:when test="$char = '-'">
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,'J')"/>
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,'G')"/>
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,'O')"/>
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,'C')"/>
99      </xsl:call-template>
100     </xsl:when>
101     <xsl:otherwise>
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,$char)"/>
105      </xsl:call-template>
106     </xsl:otherwise>
107    </xsl:choose>
108   </xsl:otherwise>
109  </xsl:choose>
110 </xsl:template>
111
112 <!-- The next function is used to quote URIs to embed them in an URL -->
113 <xsl:template name="quote_url">
114  <xsl:param name="s" select="''"/>
115  <xsl:param name="news" select="''"/>
116  <xsl:choose>
117   <xsl:when test="$s = ''"><xsl:value-of select="$news"/></xsl:when>
118   <xsl:otherwise>
119    <xsl:variable name="char" select="substring($s,1,1)"/>
120    <xsl:choose>
121     <xsl:when test="$char = '#'">
122      <xsl:call-template name="quote_url">
123       <xsl:with-param name="s" select="substring($s,2)"/>
124       <xsl:with-param name="news" select="concat($news,'%23')"/>
125      </xsl:call-template>
126     </xsl:when>
127     <xsl:otherwise>
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,$char)"/>
131      </xsl:call-template>
132     </xsl:otherwise>
133    </xsl:choose>
134   </xsl:otherwise>
135  </xsl:choose>
136 </xsl:template>
137
138 <xsl:template name="RDFURI_of_CICURI">
139  <xsl:param name="uri" select="''"/>
140  <xsl:variable name="before" select="substring-before($uri,'#xpointer(1/')"/>
141  <xsl:value-of select="$base_RDF_URI"/>
142  <xsl:choose>
143   <xsl:when test="$before=''">
144    <xsl:value-of select="$uri"/>
145   </xsl:when>
146   <xsl:otherwise>
147    <xsl:value-of select="concat($before,',')"/>
148    <xsl:variable name="after" select="substring-after($uri,'#xpointer(1/')"/>
149    <xsl:value-of select="translate(substring-before($after,')'),'/',',')"/>
150   </xsl:otherwise>
151  </xsl:choose>
152 </xsl:template>
153
154 <xsl:template match="/">
155  <!--
156  <xsl:text>strict digraph L0 { size = "83,83"; concentrate=true; node [style=filled, shape = box];&#x0A;</xsl:text>
157  -->
158  <xsl:text>strict digraph L0 { size = "83,83"; node [style=filled, shape = box];&#x0A;</xsl:text>
159  <xsl:variable name="quoted_CICURI">
160   <xsl:call-template name="quote_url">
161    <xsl:with-param name="s" select="$CICURI"/>
162   </xsl:call-template>
163  </xsl:variable>
164  <!-- The nonce is used to force the document reload -->
165  <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))"/>
166  <xsl:variable name="dummy1" select="document(concat($uri_set_queueURL,'add_if_not_in?uri=',$quoted_CICURI,'&amp;nonce=',generate-id(),'&amp;PID=',$PID))"/>
167  <xsl:apply-templates mode="loop" select="document(concat($uri_set_queueURL,'get_next?uri=',$quoted_CICURI,'&amp;nonce=',generate-id(),'&amp;PID=',$PID))"/>
168  <xsl:variable name="dummy2" select="document(concat($uri_set_queueURL,'reset_to_empty?PID=',$PID))"/>
169  <xsl:text>}</xsl:text>
170 </xsl:template>
171
172 <xsl:template mode="loop" match="empty"/>
173
174 <xsl:template mode="loop" match="uri|marked_uri">
175  <xsl:variable name="rdfuri">
176   <xsl:call-template name="RDFURI_of_CICURI">
177    <xsl:with-param name="uri" select="@value"/>
178   </xsl:call-template>
179  </xsl:variable>
180  <xsl:variable name="document" select="document(concat($base_URL_of_URI,$rdfuri))"/>
181  <xsl:choose>
182   <xsl:when test="$document/*">
183    <xsl:apply-templates mode="first_time" select="$document/*">
184     <xsl:with-param name="currentCICURI" select="@value"/>
185     <xsl:with-param name="quotedCurrentCICURI">
186      <xsl:call-template name="quote">
187       <xsl:with-param name="s" select="@value"/>
188      </xsl:call-template>
189     </xsl:with-param>
190     <xsl:with-param name="do_not_visit" select="name(.)"/>
191    </xsl:apply-templates>
192   </xsl:when>
193   <xsl:otherwise>
194    <xsl:apply-templates mode="first_time" select=".">
195     <xsl:with-param name="currentCICURI" select="@value"/>
196     <xsl:with-param name="quotedCurrentCICURI">
197      <xsl:call-template name="quote">
198       <xsl:with-param name="s" select="@value"/>
199      </xsl:call-template>
200     </xsl:with-param>
201     <xsl:with-param name="do_not_visit" select="'no_deps'"/>
202    </xsl:apply-templates>
203   </xsl:otherwise>
204  </xsl:choose>
205  <xsl:variable name="quoted_value">
206   <xsl:call-template name="quote_url">
207    <xsl:with-param name="s" select="@value"/>
208   </xsl:call-template>
209  </xsl:variable>
210  <!-- The couple (uri,nonce) is used to force the document reload -->
211  <xsl:apply-templates mode="loop" select="document(concat($uri_set_queueURL,'get_next?uri=',$quoted_value,'&amp;nonce=',generate-id(),'&amp;PID=',$PID))"/>
212 </xsl:template>
213
214
215 <xsl:template mode="first_time" match="*">
216  <xsl:param name="currentCICURI" select="''"/>
217  <xsl:param name="quotedCurrentCICURI" select="''"/>
218  <xsl:param name="do_not_visit" select="'uri'"/>
219  <xsl:if test="$do_not_visit='uri'">
220   <xsl:apply-templates select=".">
221    <xsl:with-param name="currentCICURI" select="$currentCICURI"/>
222    <xsl:with-param name="quotedCurrentCICURI" select="$quotedCurrentCICURI"/>
223   </xsl:apply-templates>
224  </xsl:if>
225  <xsl:text> </xsl:text>
226  <xsl:value-of select="$quotedCurrentCICURI"/>
227 <!-- <xsl:text> [fontname="LucidaSansRegular",color=red,label="</xsl:text> -->
228  <xsl:text> [label="</xsl:text>
229  <xsl:value-of select="$currentCICURI"/>
230  <xsl:text>",URL="</xsl:text>
231  <xsl:value-of select="$currentCICURI"/>
232  <xsl:text>"</xsl:text>
233  <xsl:if test="name(document(concat($uri_set_queueURL,'is_overflowed?uri=',$quotedCurrentCICURI,'&amp;nonce=',generate-id(),'&amp;PID=',$PID))/*)='true'">
234   <xsl:text>,color=red</xsl:text>
235  </xsl:if>
236  <xsl:text>];&#x0A;</xsl:text>
237 </xsl:template>
238
239 <xsl:template match="*">
240  <xsl:param name="currentCICURI" select="''"/>
241  <xsl:param name="quotedCurrentCICURI" select="''"/>
242  <xsl:for-each select="*/*/*">
243   <xsl:variable name="quotedURI">
244    <xsl:call-template name="quote">
245     <xsl:with-param name="s" select="h:occurrence"/>
246    </xsl:call-template>
247   </xsl:variable>
248   <xsl:variable name="quoted_uri">
249    <xsl:call-template name="quote_url">
250     <xsl:with-param name="s" select="h:occurrence"/>
251    </xsl:call-template>
252   </xsl:variable>
253   <!-- The nonce, quotedCurrentCICURI are used to force the document reload -->
254   <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')">
255    <xsl:text> </xsl:text>
256    <xsl:value-of select="$quotedCurrentCICURI"/>
257    <xsl:text> -&gt; </xsl:text>
258    <xsl:value-of select="$quotedURI"/>
259    <xsl:value-of select="$link_direction"/>
260    <xsl:text>;&#x0A;</xsl:text>
261   </xsl:if>
262  </xsl:for-each>
263 </xsl:template>
264
265 </xsl:stylesheet>