source: rfc2629xslt/gen-reference-graph.xslt

Last change on this file was 2762, checked in by julian.reschke@…, 11 months ago

update specs and rfc2629.xslt

  • Property svn:eol-style set to native
File size: 17.9 KB
Line 
1<!--
2    Gen reference graph (requires local copy of "rfc-index.xml",
3    available from <ftp://ftp.isi.edu/in-notes/rfc-index.xml> and
4    "tr.rdf", available from <http://www.w3.org/2002/01/tr-automation/tr.rdf>)
5
6    Copyright (c) 2006-2021, Julian Reschke (julian.reschke@greenbytes.de)
7    All rights reserved.
8
9    Redistribution and use in source and binary forms, with or without
10    modification, are permitted provided that the following conditions are met:
11
12    * Redistributions of source code must retain the above copyright notice,
13      this list of conditions and the following disclaimer.
14    * Redistributions in binary form must reproduce the above copyright notice,
15      this list of conditions and the following disclaimer in the documentation
16      and/or other materials provided with the distribution.
17    * Neither the name of Julian Reschke nor the names of its contributors
18      may be used to endorse or promote products derived from this software
19      without specific prior written permission.
20
21    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
22    AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23    IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24    ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
25    LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26    CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27    SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28    INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29    CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
30    ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
31    POSSIBILITY OF SUCH DAMAGE.
32-->
33
34<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
35                version="1.0"
36                xmlns:dc="http://purl.org/dc/elements/1.1/"
37                xmlns:doc="http://www.w3.org/2000/10/swap/pim/doc#"
38                xmlns:ed="http://greenbytes.de/2002/rfcedit"
39                xmlns:exslt="http://exslt.org/common"
40                xmlns:rfced="http://www.rfc-editor.org/rfc-index"
41                xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
42                xmlns:tr="http://www.w3.org/2001/02pd/rec54#"
43>
44
45<xsl:output method="text" encoding="UTF-8"/>
46
47<!-- create graph for specific RFC from RFC index -->
48<xsl:param name="rfc"/>
49
50<!-- character translation tables -->
51<xsl:variable name="lcase" select="'abcdefghijklmnopqrstuvwxyz'" />
52<xsl:variable name="ucase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
53
54<xsl:template match="/">
55  <xsl:text>digraph </xsl:text>
56  <xsl:value-of select="translate(/rfc/@docName,'-.','__')" />
57  <xsl:text> { &#10;</xsl:text>
58  <xsl:text>  rankdir=LR;</xsl:text>
59
60  <xsl:variable name="out">
61    <xsl:choose>
62      <xsl:when test="$rfc!=''">
63        <xsl:call-template name="check-rfc-index-entry">
64          <xsl:with-param name="doc-id" select="$rfc"/>
65        </xsl:call-template>
66      </xsl:when>
67      <xsl:otherwise>
68        <xsl:for-each select="//references">
69          <xsl:variable name="title">
70            <xsl:choose>
71              <xsl:when test="@title">
72                <xsl:value-of select="@title"/>
73              </xsl:when>
74              <xsl:otherwise>
75                <xsl:text>References</xsl:text>
76              </xsl:otherwise>
77            </xsl:choose>
78          </xsl:variable>
79          <xsl:for-each select=".//reference[not(ancestor::ed:del)]">
80            <xsl:sort select="@anchor"/>
81            <xsl:choose>
82              <xsl:when test="seriesInfo/@name='RFC'">
83                <xsl:apply-templates select="." mode="check-rfc"/>
84              </xsl:when>
85              <xsl:when test="seriesInfo/@name='Internet-Draft'">
86                <!-- Nothing to do -->
87              </xsl:when>
88              <xsl:when test="seriesInfo/@name='W3C'">
89                <xsl:call-template name="check-w3c">
90                  <xsl:with-param name="serinfo" select="seriesInfo[@name='W3C']"/>
91                </xsl:call-template>
92              </xsl:when>
93              <xsl:when test="seriesInfo/@name='W3C NOTE'">
94                <xsl:message>Warning: seriesInfo/@name for W3C specs should be 'W3C', found: 'W3C NOTE'.</xsl:message>
95                <xsl:call-template name="check-w3c">
96                  <xsl:with-param name="serinfo" select="seriesInfo[@name='W3C NOTE']"/>
97                </xsl:call-template>
98              </xsl:when>
99              <xsl:when test="seriesInfo/@name='W3C REC'">
100                <xsl:message>Warning: seriesInfo/@name for W3C specs should be 'W3C', found: 'W3C REC'.</xsl:message>
101                <xsl:call-template name="check-w3c">
102                  <xsl:with-param name="serinfo" select="seriesInfo[@name='W3C REC']"/>
103                </xsl:call-template>
104              </xsl:when>
105              <xsl:when test="seriesInfo/@name='World Wide Web Consortium FirstEdition'">
106                <xsl:message>Warning: seriesInfo/@name for W3C specs should be 'W3C', found: 'World Wide Web Consortium FirstEdition'.</xsl:message>
107                <xsl:call-template name="check-w3c">
108                  <xsl:with-param name="serinfo" select="seriesInfo[@name='World Wide Web Consortium FirstEdition']"/>
109                </xsl:call-template>
110              </xsl:when>
111              <xsl:when test="seriesInfo/@name='World Wide Web Consortium Recommendation'">
112                <xsl:message>Warning: seriesInfo/@name for W3C specs should be 'W3C', found: 'World Wide Web Consortium Recommendation'.</xsl:message>
113                <xsl:call-template name="check-w3c">
114                  <xsl:with-param name="serinfo" select="seriesInfo[@name='World Wide Web Consortium Recommendation']"/>
115                </xsl:call-template>
116              </xsl:when>
117              <xsl:when test="seriesInfo/@name">
118                <xsl:message>Warning: unknown seriesInfo/@name: '<xsl:value-of select="seriesInfo/@name"/>'. </xsl:message>
119              </xsl:when>
120              <xsl:otherwise/>
121            </xsl:choose>
122          </xsl:for-each>
123        </xsl:for-each>
124      </xsl:otherwise>
125    </xsl:choose>
126
127  </xsl:variable>
128 
129  <xsl:for-each select="exslt:node-set($out)/definition">
130    <xsl:if test="not(@id = preceding-sibling::definition/@id)">
131      <xsl:value-of select="."/>
132    </xsl:if>
133  </xsl:for-each>
134  <xsl:for-each select="exslt:node-set($out)/relation">
135    <xsl:if test="not(. = preceding-sibling::relation)">
136      <xsl:value-of select="."/>
137    </xsl:if>
138  </xsl:for-each>
139
140  <xsl:text>}&#10;</xsl:text>
141</xsl:template>
142
143<xsl:template name="write-rfc-node-def">
144  <xsl:param name="node"/>
145  <xsl:variable name="boxstyle">
146    <xsl:choose>
147      <xsl:when test="$node/rfced:current-status='BEST CURRENT PRACTICE'">
148        <xsl:text>[style = filled, fillcolor = black, fontcolor=white, shape=box]</xsl:text>
149      </xsl:when>
150      <xsl:when test="$node/rfced:current-status='INFORMATIONAL'">
151        <xsl:text>[style = filled, fillcolor = lightblue]</xsl:text>
152      </xsl:when>
153      <xsl:when test="$node/rfced:current-status='EXPERIMENTAL'">
154        <xsl:text>[style = filled, fillcolor = lightcyan]</xsl:text>
155      </xsl:when>
156      <xsl:when test="$node/rfced:current-status='PROPOSED STANDARD'">
157        <xsl:text>[style = "filled,rounded", fillcolor = lightyellow, shape=box]</xsl:text>
158      </xsl:when>
159      <xsl:when test="$node/rfced:current-status='DRAFT STANDARD'">
160        <xsl:text>[style = "filled,rounded", fillcolor = orange, shape=box]</xsl:text>
161      </xsl:when>
162      <xsl:when test="$node/rfced:current-status='STANDARD' or $node/rfced:current-status='INTERNET STANDARD'">
163        <xsl:text>[style = "filled,rounded", fillcolor = palegreen1, shape=box]</xsl:text>
164      </xsl:when>
165      <xsl:otherwise></xsl:otherwise>
166    </xsl:choose>
167  </xsl:variable>
168
169  <definition id="{$node/rfced:doc-id}">
170    <xsl:text>  "</xsl:text>
171    <xsl:value-of select="$node/rfced:doc-id"/>
172    <xsl:text>" [id = "</xsl:text>
173    <xsl:value-of select="$node/rfced:doc-id"/>
174    <xsl:text>"][URL = "</xsl:text>
175    <xsl:variable name="num" select="number(substring-after(translate($node/rfced:doc-id,$ucase,$lcase),'rfc'))"/>
176    <xsl:value-of select="concat('https://www.rfc-editor.org/rfc/rfc',$num,'.html')"/>
177    <xsl:text>"][tooltip = "</xsl:text>
178    <xsl:call-template name="replace-substring">
179      <xsl:with-param name="string" select="$node/rfced:title"/>
180      <xsl:with-param name="replace">"</xsl:with-param>
181      <xsl:with-param name="by">\"</xsl:with-param>
182    </xsl:call-template>
183    <xsl:text>"]</xsl:text>
184    <xsl:value-of select="$boxstyle"/>
185    <xsl:text>;&#10;</xsl:text>
186  </definition>
187</xsl:template>
188
189<xsl:template name="write-w3c-node-def">
190  <xsl:param name="node"/>
191  <xsl:param name="doc-id"/>
192  <xsl:variable name="boxstyle">
193    <xsl:choose>
194      <xsl:when test="local-name($node) = 'NOTE'">
195        <xsl:text>[style = filled, fillcolor = blue]</xsl:text>
196      </xsl:when>
197      <xsl:when test="local-name($node) = 'FirstEdition'">
198        <xsl:text>[style = "filled,rounded", fillcolor = green, shape=box]</xsl:text>
199      </xsl:when>
200      <xsl:when test="local-name($node) = 'PER'">
201        <xsl:text>[style = "filled,rounded", fillcolor = yellow, shape=box]</xsl:text>
202      </xsl:when>
203      <xsl:when test="local-name($node) = 'REC'">
204        <xsl:text>[style = "filled,rounded", fillcolor = green, shape=box]</xsl:text>
205      </xsl:when>
206      <xsl:otherwise></xsl:otherwise>
207    </xsl:choose>
208  </xsl:variable>
209
210  <definition id="{$doc-id}">
211    <xsl:text>  "</xsl:text>
212    <xsl:value-of select="$doc-id"/>
213    <xsl:text>" [URL = "</xsl:text>
214    <xsl:value-of select="$node/@rdf:about"/>
215    <xsl:text>"][tooltip = "</xsl:text>
216    <xsl:value-of select="$node/dc:title"/>
217    <xsl:text>"]</xsl:text>
218    <xsl:value-of select="$boxstyle"/>
219    <xsl:text>;&#10;</xsl:text>
220  </definition>
221</xsl:template>
222
223<!-- check an RFC Index entry -->
224<xsl:template name="check-rfc-index-entry">
225  <xsl:param name="src-id"/>
226  <xsl:param name="doc-id"/>
227  <xsl:param name="title"/>
228
229  <xsl:variable name="stat" select="document('rfc-index.xml')/*/rfced:rfc-entry[rfced:doc-id=$doc-id]" />
230
231  <xsl:if test="$stat/rfced:doc-id">
232    <xsl:call-template name="write-rfc-node-def">
233      <xsl:with-param name="node" select="$stat"/>
234    </xsl:call-template>
235  </xsl:if>
236
237  <xsl:if test="$src-id">
238    <relation>
239      <xsl:text>  "</xsl:text>
240      <xsl:value-of select="$src-id"/>
241      <xsl:text>" -> "</xsl:text>
242      <xsl:value-of select="$doc-id"/>
243      <xsl:choose>
244        <xsl:when test="$title='References' or $title='Normative References'">
245          <xsl:text>" [style = solid, color = red][tooltip = "normatively references"];&#10;</xsl:text>
246        </xsl:when>
247        <xsl:when test="$title!=''">
248          <xsl:text>" [style = solid][tooltip = "informatively references"];&#10;</xsl:text>
249        </xsl:when>
250        <xsl:otherwise>
251          <xsl:text>" [style = solid][tooltip = "references"];&#10;</xsl:text>
252        </xsl:otherwise>
253      </xsl:choose>
254    </relation>
255  </xsl:if>
256 
257  <xsl:for-each select="$stat/rfced:updated-by/rfced:doc-id">
258    <xsl:call-template name="check-rfc-index-entry">
259      <xsl:with-param name="doc-id" select="."/>
260    </xsl:call-template>
261    <relation>
262      <xsl:text>  "</xsl:text>
263      <xsl:value-of select="$doc-id"/>
264      <xsl:text>" -> "</xsl:text>
265      <xsl:value-of select="."/>
266      <xsl:text>" [style = dotted, dir = back, tooltip = "updates"];&#10;</xsl:text>
267    </relation>
268  </xsl:for-each>
269  <xsl:for-each select="$stat/rfced:obsoleted-by/rfced:doc-id">
270    <xsl:call-template name="check-rfc-index-entry">
271      <xsl:with-param name="doc-id" select="."/>
272    </xsl:call-template>
273    <relation>
274      <xsl:text>  "</xsl:text>
275      <xsl:value-of select="$doc-id"/>
276      <xsl:text>" -> "</xsl:text>
277      <xsl:value-of select="."/>
278      <xsl:text>" [style = dashed, dir = back, tooltip = "obsoletes"];&#10;</xsl:text>
279    </relation>
280  </xsl:for-each>
281 
282</xsl:template>
283
284<!-- check a W3C Index entry -->
285<xsl:template name="check-w3c-index-entry">
286  <xsl:param name="src-id"/>
287  <xsl:param name="doc-id"/>
288  <xsl:param name="title"/>
289
290  <xsl:variable name="stat" select="document('tr.rdf')//*[substring(@rdf:about, string-length(@rdf:about) - string-length($doc-id) + 1) = $doc-id
291    or substring(@rdf:about, string-length(@rdf:about) - string-length($doc-id)) = concat($doc-id,'/')]" />
292
293  <xsl:if test="$stat">
294    <xsl:call-template name="write-w3c-node-def">
295      <xsl:with-param name="node" select="$stat"/>
296      <xsl:with-param name="doc-id" select="$doc-id"/>
297    </xsl:call-template>
298  </xsl:if>
299
300  <xsl:if test="$src-id">
301    <relation>
302      <xsl:text>  "</xsl:text>
303      <xsl:value-of select="$src-id"/>
304      <xsl:text>" -> "</xsl:text>
305      <xsl:value-of select="$doc-id"/>
306      <xsl:choose>
307        <xsl:when test="$title='References' or $title='Normative References'">
308          <xsl:text>" [style = solid, color = red][tooltip = "normatively references"];&#10;</xsl:text>
309        </xsl:when>
310        <xsl:when test="$title!=''">
311          <xsl:text>" [style = solid][tooltip = "informatively references"];&#10;</xsl:text>
312        </xsl:when>
313        <xsl:otherwise>
314          <xsl:text>" [style = solid][tooltip = "references"];&#10;</xsl:text>
315        </xsl:otherwise>
316      </xsl:choose>
317    </relation>
318  </xsl:if>
319 
320  <xsl:for-each select="document('tr.rdf')//*[tr:previousEdition/@rdf:resource=$stat/@rdf:about]">
321    <xsl:variable name="ref-short-name">
322      <xsl:call-template name="last-segment">
323        <xsl:with-param name="s" select="@rdf:about"/>
324      </xsl:call-template>
325    </xsl:variable>
326<!--<xsl:message><xsl:value-of select="./@rdf:about"/> is a previous version of <xsl:value-of select="$stat/@rdf:about"/></xsl:message>-->
327    <xsl:call-template name="check-w3c-index-entry">
328      <xsl:with-param name="doc-id" select="$ref-short-name"/>
329    </xsl:call-template>
330    <relation>
331      <xsl:text>  "</xsl:text>
332      <xsl:value-of select="$doc-id"/>
333      <xsl:text>" -> "</xsl:text>
334      <xsl:value-of select="$ref-short-name"/>
335      <xsl:text>" [style = dashed, dir = back, tooltip = "obsoletes"];&#10;</xsl:text>
336    </relation>
337  </xsl:for-each>
338</xsl:template>
339
340<xsl:template name="last-segment">
341  <xsl:param name="s"/>
342  <xsl:choose>
343    <xsl:when test="contains($s,'/')">
344      <xsl:choose>
345        <xsl:when test="concat(substring-before($s,'/'),'/') = $s">
346          <xsl:value-of select="substring-before($s,'/')"/>
347        </xsl:when>
348        <xsl:otherwise>
349          <xsl:call-template name="last-segment">
350            <xsl:with-param name="s" select="substring-after($s,'/')"/>
351          </xsl:call-template>
352        </xsl:otherwise>
353      </xsl:choose>
354    </xsl:when>
355    <xsl:otherwise>
356      <xsl:value-of select="$s"/>
357    </xsl:otherwise>
358  </xsl:choose>
359</xsl:template>
360
361<!-- check RFC reference -->
362<xsl:template match="reference" mode="check-rfc">
363  <xsl:variable name="no" select="seriesInfo[@name='RFC']/@value" />
364  <xsl:variable name="id" select="concat('RFC',substring('000',string-length($no)),$no)" />
365  <xsl:variable name="title">
366    <xsl:choose>
367      <xsl:when test="ancestor::references/@title">
368        <xsl:value-of select="ancestor::references/@title"/>
369      </xsl:when>
370      <xsl:otherwise>
371        <xsl:text>References</xsl:text>
372      </xsl:otherwise>
373    </xsl:choose>
374  </xsl:variable>
375 
376  <xsl:if test="/rfc/@docName">
377    <xsl:call-template name="check-rfc-index-entry">
378      <xsl:with-param name="src-id" select="/rfc/@docName"/>
379      <xsl:with-param name="doc-id" select="$id"/>
380      <xsl:with-param name="title" select="$title"/>
381    </xsl:call-template>
382  </xsl:if>
383  <xsl:if test="/rfc/@number">
384    <xsl:call-template name="check-rfc-index-entry">
385      <xsl:with-param name="src-id" select="concat('RFC',/rfc/@number)"/>
386      <xsl:with-param name="doc-id" select="$id"/>
387      <xsl:with-param name="title" select="$title"/>
388    </xsl:call-template>
389  </xsl:if>
390</xsl:template>
391
392<!-- check W3C reference -->
393<xsl:template name="check-w3c">
394  <xsl:param name="serinfo"/>
395  <xsl:variable name="short-name">
396    <xsl:choose>
397      <xsl:when test="starts-with($serinfo/@value,'W3C.')">
398        <xsl:message>WARNING: seriesInfo/@value should be a valid 'short name', such as 'REC-webarch-20041215', found: '<xsl:value-of select="$serinfo/@value"/>'.</xsl:message>
399        <xsl:value-of select="substring-after($serinfo/@value,'W3C.')"/>
400      </xsl:when>
401      <xsl:otherwise>
402        <xsl:value-of select="$serinfo/@value"/>
403      </xsl:otherwise>
404    </xsl:choose>
405  </xsl:variable>
406
407  <xsl:variable name="title">
408    <xsl:choose>
409      <xsl:when test="ancestor::references/@title">
410        <xsl:value-of select="ancestor::references/@title"/>
411      </xsl:when>
412      <xsl:otherwise>
413        <xsl:text>References</xsl:text>
414      </xsl:otherwise>
415    </xsl:choose>
416  </xsl:variable>
417 
418  <xsl:if test="/rfc/@docName">
419    <xsl:call-template name="check-w3c-index-entry">
420      <xsl:with-param name="src-id" select="/rfc/@docName"/>
421      <xsl:with-param name="doc-id" select="$short-name"/>
422      <xsl:with-param name="title" select="$title"/>
423    </xsl:call-template>
424  </xsl:if>
425  <xsl:if test="/rfc/@number">
426    <xsl:call-template name="check-w3c-index-entry">
427      <xsl:with-param name="src-id" select="concat('RFC',/rfc/@number)"/>
428      <xsl:with-param name="doc-id" select="$short-name"/>
429      <xsl:with-param name="title" select="$title"/>
430    </xsl:call-template>
431  </xsl:if>
432 
433</xsl:template>
434
435<xsl:template name="replace-substring">
436  <xsl:param name="string" />
437  <xsl:param name="replace" />
438  <xsl:param name="by" />
439
440  <xsl:choose>
441    <xsl:when test="contains($string,$replace)">
442      <xsl:value-of select="concat(substring-before($string, $replace),$by)" />
443      <xsl:call-template name="replace-substring">
444        <xsl:with-param name="string" select="substring-after($string,$replace)" />
445        <xsl:with-param name="replace" select="$replace" />
446        <xsl:with-param name="by" select="$by" />
447      </xsl:call-template>
448    </xsl:when>
449    <xsl:otherwise><xsl:value-of select="$string" /></xsl:otherwise>
450  </xsl:choose>
451
452</xsl:template>
453
454</xsl:transform>
Note: See TracBrowser for help on using the repository browser.