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