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

Last change on this file since 24 was 6, checked in by fielding@…, 15 years ago

XSLT stylesheet for enhanced RFC2629 xml2rfc output as HTML.
By Julian Reschke

Obtained from: wget -N http://www.greenbytes.de/tech/webdav/rfc2629xslt.zip

  • Property svn:eol-style set to native
File size: 16.5 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-2007, 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:value-of select="$node/rfced:title"/>
171    <xsl:text>"]</xsl:text>
172    <xsl:value-of select="$boxstyle"/>
173    <xsl:text>;&#10;</xsl:text>
174  </definition>
175</xsl:template>
176
177<xsl:template name="write-w3c-node-def">
178  <xsl:param name="node"/>
179  <xsl:param name="doc-id"/>
180  <xsl:variable name="boxstyle">
181    <xsl:choose>
182      <xsl:when test="local-name($node) = 'NOTE'">
183        <xsl:text>[style = filled, fillcolor = blue]</xsl:text>
184      </xsl:when>
185      <xsl:when test="local-name($node) = 'FirstEdition'">
186        <xsl:text>[style = "filled,rounded", fillcolor = green, shape=box]</xsl:text>
187      </xsl:when>
188      <xsl:when test="local-name($node) = 'PER'">
189        <xsl:text>[style = "filled,rounded", fillcolor = yellow, shape=box]</xsl:text>
190      </xsl:when>
191      <xsl:when test="local-name($node) = 'REC'">
192        <xsl:text>[style = "filled,rounded", fillcolor = green, shape=box]</xsl:text>
193      </xsl:when>
194      <xsl:otherwise></xsl:otherwise>
195    </xsl:choose>
196  </xsl:variable>
197
198  <definition id="{$doc-id}">
199    <xsl:text>  "</xsl:text>
200    <xsl:value-of select="$doc-id"/>
201    <xsl:text>" [URL = "</xsl:text>
202    <xsl:value-of select="$node/@rdf:about"/>
203    <xsl:text>"][tooltip = "</xsl:text>
204    <xsl:value-of select="$node/dc:title"/>
205    <xsl:text>"]</xsl:text>
206    <xsl:value-of select="$boxstyle"/>
207    <xsl:text>;&#10;</xsl:text>
208  </definition>
209</xsl:template>
210
211<!-- check an RFC Index entry -->
212<xsl:template name="check-rfc-index-entry">
213  <xsl:param name="src-id"/>
214  <xsl:param name="doc-id"/>
215  <xsl:param name="title"/>
216
217  <xsl:variable name="stat" select="document('rfc-index.xml')/*/rfced:rfc-entry[rfced:doc-id=$doc-id]" />
218
219  <xsl:if test="$stat/rfced:doc-id">
220    <xsl:call-template name="write-rfc-node-def">
221      <xsl:with-param name="node" select="$stat"/>
222    </xsl:call-template>
223  </xsl:if>
224
225  <xsl:if test="$src-id">
226    <relation>
227      <xsl:text>  "</xsl:text>
228      <xsl:value-of select="$src-id"/>
229      <xsl:text>" -> "</xsl:text>
230      <xsl:value-of select="$doc-id"/>
231      <xsl:choose>
232        <xsl:when test="$title='References' or $title='Normative References'">
233          <xsl:text>" [style = solid, color = red][tooltip = "normatively references"];&#10;</xsl:text>
234        </xsl:when>
235        <xsl:when test="$title!=''">
236          <xsl:text>" [style = solid][tooltip = "informatively references"];&#10;</xsl:text>
237        </xsl:when>
238        <xsl:otherwise>
239          <xsl:text>" [style = solid][tooltip = "references"];&#10;</xsl:text>
240        </xsl:otherwise>
241      </xsl:choose>
242    </relation>
243  </xsl:if>
244 
245  <xsl:for-each select="$stat/rfced:updated-by/rfced:doc-id">
246    <xsl:call-template name="check-rfc-index-entry">
247      <xsl:with-param name="doc-id" select="."/>
248    </xsl:call-template>
249    <relation>
250      <xsl:text>  "</xsl:text>
251      <xsl:value-of select="$doc-id"/>
252      <xsl:text>" -> "</xsl:text>
253      <xsl:value-of select="."/>
254      <xsl:text>" [style = dotted, dir = back, tooltip = "updates"];&#10;</xsl:text>
255    </relation>
256  </xsl:for-each>
257  <xsl:for-each select="$stat/rfced:obsoleted-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 = dashed, dir = back, tooltip = "obsoletes"];&#10;</xsl:text>
267    </relation>
268  </xsl:for-each>
269 
270</xsl:template>
271
272<!-- check a W3C Index entry -->
273<xsl:template name="check-w3c-index-entry">
274  <xsl:param name="src-id"/>
275  <xsl:param name="doc-id"/>
276  <xsl:param name="title"/>
277
278  <xsl:variable name="stat" select="document('tr.rdf')//*[substring(@rdf:about, string-length(@rdf:about) - string-length($doc-id) + 1) = $doc-id
279    or substring(@rdf:about, string-length(@rdf:about) - string-length($doc-id)) = concat($doc-id,'/')]" />
280
281  <xsl:if test="$stat">
282    <xsl:call-template name="write-w3c-node-def">
283      <xsl:with-param name="node" select="$stat"/>
284      <xsl:with-param name="doc-id" select="$doc-id"/>
285    </xsl:call-template>
286  </xsl:if>
287
288  <xsl:if test="$src-id">
289    <relation>
290      <xsl:text>  "</xsl:text>
291      <xsl:value-of select="$src-id"/>
292      <xsl:text>" -> "</xsl:text>
293      <xsl:value-of select="$doc-id"/>
294      <xsl:choose>
295        <xsl:when test="$title='References' or $title='Normative References'">
296          <xsl:text>" [style = solid, color = red][tooltip = "normatively references"];&#10;</xsl:text>
297        </xsl:when>
298        <xsl:when test="$title!=''">
299          <xsl:text>" [style = solid][tooltip = "informatively references"];&#10;</xsl:text>
300        </xsl:when>
301        <xsl:otherwise>
302          <xsl:text>" [style = solid][tooltip = "references"];&#10;</xsl:text>
303        </xsl:otherwise>
304      </xsl:choose>
305    </relation>
306  </xsl:if>
307 
308  <xsl:for-each select="document('tr.rdf')//*[tr:previousEdition/@rdf:resource=$stat/@rdf:about]">
309    <xsl:variable name="ref-short-name">
310      <xsl:call-template name="last-segment">
311        <xsl:with-param name="s" select="@rdf:about"/>
312      </xsl:call-template>
313    </xsl:variable>
314<!--<xsl:message><xsl:value-of select="./@rdf:about"/> is a previous version of <xsl:value-of select="$stat/@rdf:about"/></xsl:message>-->
315    <xsl:call-template name="check-w3c-index-entry">
316      <xsl:with-param name="doc-id" select="$ref-short-name"/>
317    </xsl:call-template>
318    <relation>
319      <xsl:text>  "</xsl:text>
320      <xsl:value-of select="$doc-id"/>
321      <xsl:text>" -> "</xsl:text>
322      <xsl:value-of select="$ref-short-name"/>
323      <xsl:text>" [style = dashed, dir = back, tooltip = "obsoletes"];&#10;</xsl:text>
324    </relation>
325  </xsl:for-each>
326</xsl:template>
327
328<xsl:template name="last-segment">
329  <xsl:param name="s"/>
330  <xsl:choose>
331    <xsl:when test="contains($s,'/')">
332      <xsl:choose>
333        <xsl:when test="concat(substring-before($s,'/'),'/') = $s">
334          <xsl:value-of select="substring-before($s,'/')"/>
335        </xsl:when>
336        <xsl:otherwise>
337          <xsl:call-template name="last-segment">
338            <xsl:with-param name="s" select="substring-after($s,'/')"/>
339          </xsl:call-template>
340        </xsl:otherwise>
341      </xsl:choose>
342    </xsl:when>
343    <xsl:otherwise>
344      <xsl:value-of select="$s"/>
345    </xsl:otherwise>
346  </xsl:choose>
347</xsl:template>
348
349<!-- check RFC reference -->
350<xsl:template match="reference" mode="check-rfc">
351  <xsl:variable name="no" select="seriesInfo[@name='RFC']/@value" />
352  <xsl:variable name="id" select="concat('RFC',substring('000',string-length($no)),$no)" />
353  <xsl:variable name="title">
354    <xsl:choose>
355      <xsl:when test="ancestor::references/@title">
356        <xsl:value-of select="ancestor::references/@title"/>
357      </xsl:when>
358      <xsl:otherwise>
359        <xsl:text>References</xsl:text>
360      </xsl:otherwise>
361    </xsl:choose>
362  </xsl:variable>
363 
364  <xsl:if test="/rfc/@docName">
365    <xsl:call-template name="check-rfc-index-entry">
366      <xsl:with-param name="src-id" select="/rfc/@docName"/>
367      <xsl:with-param name="doc-id" select="$id"/>
368      <xsl:with-param name="title" select="$title"/>
369    </xsl:call-template>
370  </xsl:if>
371  <xsl:if test="/rfc/@number">
372    <xsl:call-template name="check-rfc-index-entry">
373      <xsl:with-param name="src-id" select="concat('RFC',/rfc/@number)"/>
374      <xsl:with-param name="doc-id" select="$id"/>
375      <xsl:with-param name="title" select="$title"/>
376    </xsl:call-template>
377  </xsl:if>
378</xsl:template>
379
380<!-- check W3C reference -->
381<xsl:template name="check-w3c">
382  <xsl:param name="serinfo"/>
383  <xsl:variable name="short-name">
384    <xsl:choose>
385      <xsl:when test="starts-with($serinfo/@value,'W3C.')">
386        <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>
387        <xsl:value-of select="substring-after($serinfo/@value,'W3C.')"/>
388      </xsl:when>
389      <xsl:otherwise>
390        <xsl:value-of select="$serinfo/@value"/>
391      </xsl:otherwise>
392    </xsl:choose>
393  </xsl:variable>
394
395  <xsl:variable name="title">
396    <xsl:choose>
397      <xsl:when test="ancestor::references/@title">
398        <xsl:value-of select="ancestor::references/@title"/>
399      </xsl:when>
400      <xsl:otherwise>
401        <xsl:text>References</xsl:text>
402      </xsl:otherwise>
403    </xsl:choose>
404  </xsl:variable>
405 
406  <xsl:if test="/rfc/@docName">
407    <xsl:call-template name="check-w3c-index-entry">
408      <xsl:with-param name="src-id" select="/rfc/@docName"/>
409      <xsl:with-param name="doc-id" select="$short-name"/>
410      <xsl:with-param name="title" select="$title"/>
411    </xsl:call-template>
412  </xsl:if>
413  <xsl:if test="/rfc/@number">
414    <xsl:call-template name="check-w3c-index-entry">
415      <xsl:with-param name="src-id" select="concat('RFC',/rfc/@number)"/>
416      <xsl:with-param name="doc-id" select="$short-name"/>
417      <xsl:with-param name="title" select="$title"/>
418    </xsl:call-template>
419  </xsl:if>
420 
421</xsl:template>
422
423</xsl:transform>
Note: See TracBrowser for help on using the repository browser.