source: rfc2629xslt/gen-reference-graph.xslt @ 2512

Last change on this file since 2512 was 2218, checked in by julian.reschke@…, 7 years ago

bump up document dates, update to latest version of rfc2629.xslt

  • Property svn:eol-style set to native
File size: 17.4 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-2013, 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:msxsl="urn:schemas-microsoft-com:xslt"
41                xmlns:rfced="http://www.rfc-editor.org/rfc-index"
42                xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
43                xmlns:tr="http://www.w3.org/2001/02pd/rec54#"
44>
45
46<xsl:output method="text" encoding="UTF-8"/>
47
48<!-- character translation tables -->
49<xsl:variable name="lcase" select="'abcdefghijklmnopqrstuvwxyz'" />
50<xsl:variable name="ucase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />
51
52<!-- define exslt:node-set for msxml -->       
53<msxsl:script language="JScript" implements-prefix="exslt">
54  this['node-set'] = function (x) {
55    return x;
56  }
57</msxsl:script>
58
59<xsl:template match="/">
60  <xsl:text>digraph </xsl:text>
61  <xsl:value-of select="translate(/rfc/@docName,'-.','__')" />
62  <xsl:text> { &#10;</xsl:text>
63  <xsl:text>  rankdir=LR;</xsl:text>
64
65  <xsl:variable name="out">
66    <xsl:for-each select="//references">
67      <xsl:variable name="title">
68        <xsl:choose>
69          <xsl:when test="@title">
70            <xsl:value-of select="@title"/>
71          </xsl:when>
72          <xsl:otherwise>
73            <xsl:text>References</xsl:text>
74          </xsl:otherwise>
75        </xsl:choose>
76      </xsl:variable>
77      <xsl:for-each select=".//reference[not(ancestor::ed:del)]">
78        <xsl:sort select="@anchor"/>
79        <xsl:choose>
80          <xsl:when test="seriesInfo/@name='RFC'">
81            <xsl:apply-templates select="." mode="check-rfc"/>
82          </xsl:when>
83          <xsl:when test="seriesInfo/@name='Internet-Draft'">
84            <!-- Nothing to do -->
85          </xsl:when>
86          <xsl:when test="seriesInfo/@name='W3C'">
87            <xsl:call-template name="check-w3c">
88              <xsl:with-param name="serinfo" select="seriesInfo[@name='W3C']"/>
89            </xsl:call-template>
90          </xsl:when>
91          <xsl:when test="seriesInfo/@name='W3C NOTE'">
92            <xsl:message>Warning: seriesInfo/@name for W3C specs should be 'W3C', found: 'W3C NOTE'.</xsl:message>
93            <xsl:call-template name="check-w3c">
94              <xsl:with-param name="serinfo" select="seriesInfo[@name='W3C NOTE']"/>
95            </xsl:call-template>
96          </xsl:when>
97          <xsl:when test="seriesInfo/@name='W3C REC'">
98            <xsl:message>Warning: seriesInfo/@name for W3C specs should be 'W3C', found: 'W3C REC'.</xsl:message>
99            <xsl:call-template name="check-w3c">
100              <xsl:with-param name="serinfo" select="seriesInfo[@name='W3C REC']"/>
101            </xsl:call-template>
102          </xsl:when>
103          <xsl:when test="seriesInfo/@name='World Wide Web Consortium FirstEdition'">
104            <xsl:message>Warning: seriesInfo/@name for W3C specs should be 'W3C', found: 'World Wide Web Consortium FirstEdition'.</xsl:message>
105            <xsl:call-template name="check-w3c">
106              <xsl:with-param name="serinfo" select="seriesInfo[@name='World Wide Web Consortium FirstEdition']"/>
107            </xsl:call-template>
108          </xsl:when>
109          <xsl:when test="seriesInfo/@name='World Wide Web Consortium Recommendation'">
110            <xsl:message>Warning: seriesInfo/@name for W3C specs should be 'W3C', found: 'World Wide Web Consortium Recommendation'.</xsl:message>
111            <xsl:call-template name="check-w3c">
112              <xsl:with-param name="serinfo" select="seriesInfo[@name='World Wide Web Consortium Recommendation']"/>
113            </xsl:call-template>
114          </xsl:when>
115          <xsl:when test="seriesInfo/@name">
116            <xsl:message>Warning: unknown seriesInfo/@name: '<xsl:value-of select="seriesInfo/@name"/>'. </xsl:message>
117          </xsl:when>
118          <xsl:otherwise/>
119        </xsl:choose>
120      </xsl:for-each>
121    </xsl:for-each>
122  </xsl:variable>
123 
124  <xsl:for-each select="exslt:node-set($out)/definition">
125    <xsl:if test="not(@id = preceding-sibling::definition/@id)">
126      <xsl:value-of select="."/>
127    </xsl:if>
128  </xsl:for-each>
129  <xsl:for-each select="exslt:node-set($out)/relation">
130    <xsl:if test="not(. = preceding-sibling::relation)">
131      <xsl:value-of select="."/>
132    </xsl:if>
133  </xsl:for-each>
134
135  <xsl:text>}&#10;</xsl:text>
136</xsl:template>
137
138<xsl:template name="write-rfc-node-def">
139  <xsl:param name="node"/>
140  <xsl:variable name="boxstyle">
141    <xsl:choose>
142      <xsl:when test="$node/rfced:current-status='BEST CURRENT PRACTICE'">
143        <xsl:text>[style = filled, fillcolor = black, fontcolor=white, shape=box]</xsl:text>
144      </xsl:when>
145      <xsl:when test="$node/rfced:current-status='INFORMATIONAL'">
146        <xsl:text>[style = filled, fillcolor = blue]</xsl:text>
147      </xsl:when>
148      <xsl:when test="$node/rfced:current-status='EXPERIMENTAL'">
149        <xsl:text>[style = filled, fillcolor = cyan]</xsl:text>
150      </xsl:when>
151      <xsl:when test="$node/rfced:current-status='PROPOSED STANDARD'">
152        <xsl:text>[style = "filled,rounded", fillcolor = yellow, shape=box]</xsl:text>
153      </xsl:when>
154      <xsl:when test="$node/rfced:current-status='DRAFT STANDARD'">
155        <xsl:text>[style = "filled,rounded", fillcolor = orange, shape=box]</xsl:text>
156      </xsl:when>
157      <xsl:when test="$node/rfced:current-status='STANDARD'">
158        <xsl:text>[style = "filled,rounded", fillcolor = green, shape=box]</xsl:text>
159      </xsl:when>
160      <xsl:otherwise></xsl:otherwise>
161    </xsl:choose>
162  </xsl:variable>
163
164  <definition id="{$node/rfced:doc-id}">
165    <xsl:text>  "</xsl:text>
166    <xsl:value-of select="$node/rfced:doc-id"/>
167    <xsl:text>" [URL = "</xsl:text>
168    <xsl:value-of select="concat('http://tools.ietf.org/html/',translate($node/rfced:doc-id,$ucase,$lcase))"/>
169    <xsl:text>"][tooltip = "</xsl:text>
170    <xsl:call-template name="replace-substring">
171      <xsl:with-param name="string" select="$node/rfced:title"/>
172      <xsl:with-param name="replace">"</xsl:with-param>
173      <xsl:with-param name="by">\"</xsl:with-param>
174    </xsl:call-template>
175    <xsl:text>"]</xsl:text>
176    <xsl:value-of select="$boxstyle"/>
177    <xsl:text>;&#10;</xsl:text>
178  </definition>
179</xsl:template>
180
181<xsl:template name="write-w3c-node-def">
182  <xsl:param name="node"/>
183  <xsl:param name="doc-id"/>
184  <xsl:variable name="boxstyle">
185    <xsl:choose>
186      <xsl:when test="local-name($node) = 'NOTE'">
187        <xsl:text>[style = filled, fillcolor = blue]</xsl:text>
188      </xsl:when>
189      <xsl:when test="local-name($node) = 'FirstEdition'">
190        <xsl:text>[style = "filled,rounded", fillcolor = green, shape=box]</xsl:text>
191      </xsl:when>
192      <xsl:when test="local-name($node) = 'PER'">
193        <xsl:text>[style = "filled,rounded", fillcolor = yellow, shape=box]</xsl:text>
194      </xsl:when>
195      <xsl:when test="local-name($node) = 'REC'">
196        <xsl:text>[style = "filled,rounded", fillcolor = green, shape=box]</xsl:text>
197      </xsl:when>
198      <xsl:otherwise></xsl:otherwise>
199    </xsl:choose>
200  </xsl:variable>
201
202  <definition id="{$doc-id}">
203    <xsl:text>  "</xsl:text>
204    <xsl:value-of select="$doc-id"/>
205    <xsl:text>" [URL = "</xsl:text>
206    <xsl:value-of select="$node/@rdf:about"/>
207    <xsl:text>"][tooltip = "</xsl:text>
208    <xsl:value-of select="$node/dc:title"/>
209    <xsl:text>"]</xsl:text>
210    <xsl:value-of select="$boxstyle"/>
211    <xsl:text>;&#10;</xsl:text>
212  </definition>
213</xsl:template>
214
215<!-- check an RFC Index entry -->
216<xsl:template name="check-rfc-index-entry">
217  <xsl:param name="src-id"/>
218  <xsl:param name="doc-id"/>
219  <xsl:param name="title"/>
220
221  <xsl:variable name="stat" select="document('rfc-index.xml')/*/rfced:rfc-entry[rfced:doc-id=$doc-id]" />
222
223  <xsl:if test="$stat/rfced:doc-id">
224    <xsl:call-template name="write-rfc-node-def">
225      <xsl:with-param name="node" select="$stat"/>
226    </xsl:call-template>
227  </xsl:if>
228
229  <xsl:if test="$src-id">
230    <relation>
231      <xsl:text>  "</xsl:text>
232      <xsl:value-of select="$src-id"/>
233      <xsl:text>" -> "</xsl:text>
234      <xsl:value-of select="$doc-id"/>
235      <xsl:choose>
236        <xsl:when test="$title='References' or $title='Normative References'">
237          <xsl:text>" [style = solid, color = red][tooltip = "normatively references"];&#10;</xsl:text>
238        </xsl:when>
239        <xsl:when test="$title!=''">
240          <xsl:text>" [style = solid][tooltip = "informatively references"];&#10;</xsl:text>
241        </xsl:when>
242        <xsl:otherwise>
243          <xsl:text>" [style = solid][tooltip = "references"];&#10;</xsl:text>
244        </xsl:otherwise>
245      </xsl:choose>
246    </relation>
247  </xsl:if>
248 
249  <xsl:for-each select="$stat/rfced:updated-by/rfced:doc-id">
250    <xsl:call-template name="check-rfc-index-entry">
251      <xsl:with-param name="doc-id" select="."/>
252    </xsl:call-template>
253    <relation>
254      <xsl:text>  "</xsl:text>
255      <xsl:value-of select="$doc-id"/>
256      <xsl:text>" -> "</xsl:text>
257      <xsl:value-of select="."/>
258      <xsl:text>" [style = dotted, dir = back, tooltip = "updates"];&#10;</xsl:text>
259    </relation>
260  </xsl:for-each>
261  <xsl:for-each select="$stat/rfced:obsoleted-by/rfced:doc-id">
262    <xsl:call-template name="check-rfc-index-entry">
263      <xsl:with-param name="doc-id" select="."/>
264    </xsl:call-template>
265    <relation>
266      <xsl:text>  "</xsl:text>
267      <xsl:value-of select="$doc-id"/>
268      <xsl:text>" -> "</xsl:text>
269      <xsl:value-of select="."/>
270      <xsl:text>" [style = dashed, dir = back, tooltip = "obsoletes"];&#10;</xsl:text>
271    </relation>
272  </xsl:for-each>
273 
274</xsl:template>
275
276<!-- check a W3C Index entry -->
277<xsl:template name="check-w3c-index-entry">
278  <xsl:param name="src-id"/>
279  <xsl:param name="doc-id"/>
280  <xsl:param name="title"/>
281
282  <xsl:variable name="stat" select="document('tr.rdf')//*[substring(@rdf:about, string-length(@rdf:about) - string-length($doc-id) + 1) = $doc-id
283    or substring(@rdf:about, string-length(@rdf:about) - string-length($doc-id)) = concat($doc-id,'/')]" />
284
285  <xsl:if test="$stat">
286    <xsl:call-template name="write-w3c-node-def">
287      <xsl:with-param name="node" select="$stat"/>
288      <xsl:with-param name="doc-id" select="$doc-id"/>
289    </xsl:call-template>
290  </xsl:if>
291
292  <xsl:if test="$src-id">
293    <relation>
294      <xsl:text>  "</xsl:text>
295      <xsl:value-of select="$src-id"/>
296      <xsl:text>" -> "</xsl:text>
297      <xsl:value-of select="$doc-id"/>
298      <xsl:choose>
299        <xsl:when test="$title='References' or $title='Normative References'">
300          <xsl:text>" [style = solid, color = red][tooltip = "normatively references"];&#10;</xsl:text>
301        </xsl:when>
302        <xsl:when test="$title!=''">
303          <xsl:text>" [style = solid][tooltip = "informatively references"];&#10;</xsl:text>
304        </xsl:when>
305        <xsl:otherwise>
306          <xsl:text>" [style = solid][tooltip = "references"];&#10;</xsl:text>
307        </xsl:otherwise>
308      </xsl:choose>
309    </relation>
310  </xsl:if>
311 
312  <xsl:for-each select="document('tr.rdf')//*[tr:previousEdition/@rdf:resource=$stat/@rdf:about]">
313    <xsl:variable name="ref-short-name">
314      <xsl:call-template name="last-segment">
315        <xsl:with-param name="s" select="@rdf:about"/>
316      </xsl:call-template>
317    </xsl:variable>
318<!--<xsl:message><xsl:value-of select="./@rdf:about"/> is a previous version of <xsl:value-of select="$stat/@rdf:about"/></xsl:message>-->
319    <xsl:call-template name="check-w3c-index-entry">
320      <xsl:with-param name="doc-id" select="$ref-short-name"/>
321    </xsl:call-template>
322    <relation>
323      <xsl:text>  "</xsl:text>
324      <xsl:value-of select="$doc-id"/>
325      <xsl:text>" -> "</xsl:text>
326      <xsl:value-of select="$ref-short-name"/>
327      <xsl:text>" [style = dashed, dir = back, tooltip = "obsoletes"];&#10;</xsl:text>
328    </relation>
329  </xsl:for-each>
330</xsl:template>
331
332<xsl:template name="last-segment">
333  <xsl:param name="s"/>
334  <xsl:choose>
335    <xsl:when test="contains($s,'/')">
336      <xsl:choose>
337        <xsl:when test="concat(substring-before($s,'/'),'/') = $s">
338          <xsl:value-of select="substring-before($s,'/')"/>
339        </xsl:when>
340        <xsl:otherwise>
341          <xsl:call-template name="last-segment">
342            <xsl:with-param name="s" select="substring-after($s,'/')"/>
343          </xsl:call-template>
344        </xsl:otherwise>
345      </xsl:choose>
346    </xsl:when>
347    <xsl:otherwise>
348      <xsl:value-of select="$s"/>
349    </xsl:otherwise>
350  </xsl:choose>
351</xsl:template>
352
353<!-- check RFC reference -->
354<xsl:template match="reference" mode="check-rfc">
355  <xsl:variable name="no" select="seriesInfo[@name='RFC']/@value" />
356  <xsl:variable name="id" select="concat('RFC',substring('000',string-length($no)),$no)" />
357  <xsl:variable name="title">
358    <xsl:choose>
359      <xsl:when test="ancestor::references/@title">
360        <xsl:value-of select="ancestor::references/@title"/>
361      </xsl:when>
362      <xsl:otherwise>
363        <xsl:text>References</xsl:text>
364      </xsl:otherwise>
365    </xsl:choose>
366  </xsl:variable>
367 
368  <xsl:if test="/rfc/@docName">
369    <xsl:call-template name="check-rfc-index-entry">
370      <xsl:with-param name="src-id" select="/rfc/@docName"/>
371      <xsl:with-param name="doc-id" select="$id"/>
372      <xsl:with-param name="title" select="$title"/>
373    </xsl:call-template>
374  </xsl:if>
375  <xsl:if test="/rfc/@number">
376    <xsl:call-template name="check-rfc-index-entry">
377      <xsl:with-param name="src-id" select="concat('RFC',/rfc/@number)"/>
378      <xsl:with-param name="doc-id" select="$id"/>
379      <xsl:with-param name="title" select="$title"/>
380    </xsl:call-template>
381  </xsl:if>
382</xsl:template>
383
384<!-- check W3C reference -->
385<xsl:template name="check-w3c">
386  <xsl:param name="serinfo"/>
387  <xsl:variable name="short-name">
388    <xsl:choose>
389      <xsl:when test="starts-with($serinfo/@value,'W3C.')">
390        <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>
391        <xsl:value-of select="substring-after($serinfo/@value,'W3C.')"/>
392      </xsl:when>
393      <xsl:otherwise>
394        <xsl:value-of select="$serinfo/@value"/>
395      </xsl:otherwise>
396    </xsl:choose>
397  </xsl:variable>
398
399  <xsl:variable name="title">
400    <xsl:choose>
401      <xsl:when test="ancestor::references/@title">
402        <xsl:value-of select="ancestor::references/@title"/>
403      </xsl:when>
404      <xsl:otherwise>
405        <xsl:text>References</xsl:text>
406      </xsl:otherwise>
407    </xsl:choose>
408  </xsl:variable>
409 
410  <xsl:if test="/rfc/@docName">
411    <xsl:call-template name="check-w3c-index-entry">
412      <xsl:with-param name="src-id" select="/rfc/@docName"/>
413      <xsl:with-param name="doc-id" select="$short-name"/>
414      <xsl:with-param name="title" select="$title"/>
415    </xsl:call-template>
416  </xsl:if>
417  <xsl:if test="/rfc/@number">
418    <xsl:call-template name="check-w3c-index-entry">
419      <xsl:with-param name="src-id" select="concat('RFC',/rfc/@number)"/>
420      <xsl:with-param name="doc-id" select="$short-name"/>
421      <xsl:with-param name="title" select="$title"/>
422    </xsl:call-template>
423  </xsl:if>
424 
425</xsl:template>
426
427<xsl:template name="replace-substring">
428  <xsl:param name="string" />
429  <xsl:param name="replace" />
430  <xsl:param name="by" />
431
432  <xsl:choose>
433    <xsl:when test="contains($string,$replace)">
434      <xsl:value-of select="concat(substring-before($string, $replace),$by)" />
435      <xsl:call-template name="replace-substring">
436        <xsl:with-param name="string" select="substring-after($string,$replace)" />
437        <xsl:with-param name="replace" select="$replace" />
438        <xsl:with-param name="by" select="$by" />
439      </xsl:call-template>
440    </xsl:when>
441    <xsl:otherwise><xsl:value-of select="$string" /></xsl:otherwise>
442  </xsl:choose>
443
444</xsl:template>
445
446</xsl:transform>
Note: See TracBrowser for help on using the repository browser.