source: rfc2629xslt/check-references.xslt @ 10

Last change on this file since 10 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: 12.2 KB
Line 
1<!--
2    Check RFC references (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:ed="http://greenbytes.de/2002/rfcedit"
37                xmlns:rfced="http://www.rfc-editor.org/rfc-index"
38>
39
40<xsl:output method="text" encoding="UTF-8"/>
41
42<xsl:param name="intended-level" />
43
44<xsl:template match="/">
45  <xsl:if test="$intended-level!='' and ($intended-level!='PROPOSED' and $intended-level!='DRAFT' and $intended-level!='STANDARD')">
46    <xsl:message terminate='yes'>UNKNOWN INTENDED STATUS (must be 'PROPOSED', 'DRAFT' or 'STANDARD')!</xsl:message>
47  </xsl:if>
48 
49  <xsl:for-each select="//references">
50    <xsl:variable name="title">
51      <xsl:choose>
52        <xsl:when test="@title">
53          <xsl:value-of select="@title"/>
54        </xsl:when>
55        <xsl:otherwise>
56          <xsl:text>References</xsl:text>
57        </xsl:otherwise>
58      </xsl:choose>
59    </xsl:variable>
60    <xsl:text>&#10;</xsl:text>
61    <xsl:value-of select="$title"/>
62    <xsl:text>:&#10;</xsl:text>
63    <xsl:for-each select=".//reference[not(ancestor::ed:del)]">
64      <xsl:sort select="@anchor"/>
65      <xsl:choose>
66        <xsl:when test="seriesInfo/@name='RFC'">
67          <xsl:apply-templates select="." mode="check-rfc"/>
68        </xsl:when>
69        <xsl:when test="(seriesInfo/@name='ID' or seriesInfo/@name='Internet-Draft') and starts-with(seriesInfo/@value,'draft-')">
70          <xsl:apply-templates select="." mode="check-internet-draft"/>
71        </xsl:when>
72        <xsl:when test="(seriesInfo/@name='W3C' or starts-with(seriesInfo/@name, 'W3C ') or starts-with(seriesInfo/@name, 'World Wide Web Consortium'))">
73          <xsl:apply-templates select="." mode="check-w3c"/>
74        </xsl:when>
75        <xsl:otherwise>
76          <xsl:value-of select="@anchor"/>
77          <xsl:text>: not checked&#10;</xsl:text>
78        </xsl:otherwise>
79      </xsl:choose>
80    </xsl:for-each>
81  </xsl:for-each>
82</xsl:template>
83
84<!-- helper -->
85<xsl:template name="base-name">
86  <xsl:param name="s"/>
87  <xsl:choose>
88    <xsl:when test="contains($s,'/') and substring-after($s,'/')!=''">
89      <xsl:call-template name="base-name">
90        <xsl:with-param name="s" select="substring-after($s,'/')"/>
91      </xsl:call-template>
92    </xsl:when>
93    <xsl:otherwise>
94      <xsl:value-of select="translate($s,'/','')"/>
95    </xsl:otherwise>
96  </xsl:choose>
97</xsl:template>
98
99<!-- check RFC reference -->
100<xsl:template match="reference" mode="check-rfc">
101  <xsl:variable name="title">
102    <xsl:choose>
103      <xsl:when test="ancestor::references/@title">
104        <xsl:value-of select="ancestor::references/@title"/>
105      </xsl:when>
106      <xsl:otherwise>
107        <xsl:text>References</xsl:text>
108      </xsl:otherwise>
109    </xsl:choose>
110  </xsl:variable>
111  <xsl:variable name="no" select="seriesInfo[@name='RFC']/@value" />
112  <xsl:variable name="id" select="concat('RFC',substring('000',string-length($no)),$no)" />
113  <xsl:value-of select="$id" />
114  <xsl:text>: </xsl:text>
115  <xsl:variable name="stat" select="document('rfc-index.xml')/*/rfced:rfc-entry[rfced:doc-id=$id]" />
116  <xsl:if test="$stat/rfced:current-status">
117    <xsl:text>[</xsl:text><xsl:value-of select="$stat/rfced:current-status"/><xsl:text>] </xsl:text>
118  </xsl:if>
119  <xsl:if test="$stat/rfced:is-also">
120    <xsl:text>(-> </xsl:text><xsl:value-of select="$stat/rfced:is-also/rfced:doc-id"/><xsl:text>) </xsl:text>
121  </xsl:if>
122  <xsl:choose>
123    <xsl:when test="$stat/rfced:obsoleted-by">
124      <xsl:text>obsoleted by </xsl:text>
125      <xsl:for-each select="$stat/rfced:obsoleted-by/rfced:doc-id">
126        <xsl:value-of select="."/>
127        <xsl:text> </xsl:text>
128      </xsl:for-each>
129    </xsl:when>
130    <xsl:when test="not($stat)">not found in RFC index!</xsl:when>
131
132    <!-- check the status of the normatively referred drafts -->
133    <xsl:when test="$intended-level='PROPOSED' and ($title='References' or $title='Normative References') and
134      ($stat/rfced:publication-status='PROPOSED STANDARD' or $stat/rfced:publication-status='DRAFT STANDARD' or $stat/rfced:publication-status='STANDARD' or $stat/rfced:publication-status='BEST CURRENT PRACTICE')">
135      <!-- ok -->
136    </xsl:when>
137    <xsl:when test="$intended-level='DRAFT' and ($title='References' or $title='Normative References') and
138      ($stat/rfced:publication-status='DRAFT STANDARD' or $stat/rfced:publication-status='STANDARD' or $stat/rfced:publication-status='BEST CURRENT PRACTICE')">
139      <!-- ok -->
140    </xsl:when>
141    <xsl:when test="$intended-level='STANDARD' and ($title='References' or $title='Normative References') and
142      ($stat/rfced:publication-status='STANDARD' or $stat/rfced:publication-status='BEST CURRENT PRACTICE')">
143      <!-- ok -->
144    </xsl:when>
145    <xsl:when test="$intended-level!='' and ($title='References' or $title='Normative References')">
146      <xsl:text>-- intended standards level of </xsl:text>
147      <xsl:value-of select="$intended-level"/>
148      <xsl:text> incompatible with this document's standard level!</xsl:text>
149    </xsl:when>
150    <xsl:otherwise>ok</xsl:otherwise>
151  </xsl:choose>
152  <xsl:text>&#10;</xsl:text>   
153</xsl:template>
154
155<!-- check Internet Draft reference, experimental -->
156<xsl:template match="reference" mode="check-internet-draft">
157  <xsl:variable name="name" select="seriesInfo[(@name='ID' or @name='Internet-Draft') and starts-with(@value,'draft-')]/@value" />
158  <xsl:value-of select="$name" />
159  <xsl:text>: </xsl:text>
160  <xsl:variable name="base" select="substring($name,1,string-length($name)-3)"/>
161  <xsl:variable name="number" select="substring($name,string-length($name)-1)"/>
162  <xsl:variable name="stat" select="document(concat('http://tools.ietf.org/draft/',$base,'/state.xml'))" />
163 
164  <!--stat: <xsl:value-of select="$stat/ietfdoc/info/rev"/>
165  number: <xsl:value-of select="$number"/>-->
166 
167  <xsl:choose>
168    <xsl:when test="$stat/ietfdoc/info/rev != $number">
169      <xsl:text>Alternate version available: </xsl:text><xsl:value-of select="$stat/ietfdoc/info/rev"/>
170    </xsl:when>
171    <xsl:when test="$stat/ietfdoc[state/phase='Published']">
172      <xsl:value-of select="concat('(-> RFC',$stat/ietfdoc/info/rfcnum,')')"/>
173    </xsl:when>
174    <xsl:when test="$stat/ietfdoc/state[phase='IESG' or phase='RFC-Editor']">
175      <xsl:value-of select="concat('[',$stat/ietfdoc/state/phase/@ts,' ',$stat/ietfdoc/state/phase,'] ok')"/>
176    </xsl:when>
177    <xsl:when test="$stat/ietfdoc[state/phase='ID-Exists' and info/validity='Active']">
178      <xsl:value-of select="concat('[',$stat/ietfdoc/state/phase/@ts,' ',$stat/ietfdoc/state/phase,'] ok')"/>
179    </xsl:when>
180    <xsl:when test="$stat/ietfdoc[info/validity!='Active']">
181      <xsl:value-of select="concat('[',$stat/ietfdoc/state/phase/@ts,' ',$stat/ietfdoc/state/phase,' ',$stat/ietfdoc/info/validity,'] (not active)')"/>
182    </xsl:when>
183    <xsl:otherwise>
184      <xsl:text>ID does not exist</xsl:text>
185    </xsl:otherwise>
186  </xsl:choose>
187  <xsl:text>&#10;</xsl:text>       
188</xsl:template>
189
190<xsl:template match="reference" mode="check-internet-draft-old">
191  <xsl:variable name="name" select="seriesInfo[(@name='ID' or @name='Internet-Draft') and starts-with(@value,'draft-')]/@value" />
192  <xsl:value-of select="$name" />
193  <xsl:text>: </xsl:text>
194  <xsl:variable name="stat" select="document('ietf-id-status.xml')/*/draft[@xml:id=$name]" />
195  <xsl:choose>
196    <xsl:when test="$stat[@status='active' or @status='IESG']">
197      <xsl:value-of select="concat('[',$stat/@date,' ',$stat/@status,'] ok')"/>
198    </xsl:when>
199    <xsl:when test="$stat[@status='RFC']">
200      <xsl:value-of select="concat('[',$stat/@date,' ',$stat/@status,'] (-> RFC',$stat/@num,')')"/>
201    </xsl:when>
202    <xsl:when test="$stat[@status='expired']">
203      <xsl:value-of select="concat('[',$stat/@date,' ',$stat/@status,'] expired!')"/>
204    </xsl:when>
205    <xsl:when test="$stat">
206      <xsl:value-of select="concat('[',$stat/@date,' ',$stat/@status,'] UNKNOWN STATUS!')"/>
207    </xsl:when>
208    <xsl:otherwise>
209      <xsl:variable name="base" select="substring($name,1,string-length($name)-3)"/>
210      <xsl:variable name="stat2" select="document('ietf-id-status.xml')/*/draft[starts-with(@xml:id,$base)]" />
211      <xsl:choose>
212        <xsl:when test="$stat2">
213          <xsl:text>Alternate version available: </xsl:text><xsl:value-of select="$stat2/@xml:id"/>
214        </xsl:when>
215        <xsl:otherwise>
216          <xsl:text>ID does not exist</xsl:text>
217        </xsl:otherwise>
218      </xsl:choose>     
219    </xsl:otherwise>
220  </xsl:choose>
221  <xsl:text>&#10;</xsl:text>       
222</xsl:template>
223
224<!-- check W3C reference -->
225<xsl:template match="reference" mode="check-w3c" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
226      xmlns:doc="http://www.w3.org/2000/10/swap/pim/doc#"
227      xmlns:dc="http://purl.org/dc/elements/1.1/"
228      xmlns:pd="http://www.w3.org/2001/02pd/rec54#">
229  <xsl:variable name="w3c" select="document('tr.rdf')"/>
230  <xsl:variable name="name" select="seriesInfo/@value" />
231  <xsl:value-of select="$name" />
232  <xsl:text>: </xsl:text>
233  <xsl:variable name="stat">
234    <xsl:for-each select="$w3c/*/*">
235      <xsl:variable name="t">
236        <xsl:call-template name="base-name">
237          <xsl:with-param name="s" select="@rdf:about"/>
238        </xsl:call-template>
239      </xsl:variable>
240      <xsl:if test="$t=$name">
241        <xsl:value-of select="concat(@rdf:about,' ')"/>
242      </xsl:if>
243    </xsl:for-each>
244  </xsl:variable>
245  <xsl:choose>
246    <xsl:when test="contains(normalize-space($stat),' ')">
247      <xsl:text>ambiguous match: </xsl:text><xsl:value-of select="$stat"/>
248    </xsl:when>
249    <xsl:when test="$stat!=''">
250      <xsl:variable name="basename" select="normalize-space($stat)"/>
251      <xsl:variable name="doc" select="$w3c/*/*[@rdf:about=$basename]"/>
252      <xsl:value-of select="concat('[',local-name($doc),'] ')"/>
253      <xsl:variable name="previous" select="$w3c/*/*[pd:previousEdition/@rdf:resource=$basename]"/>
254      <xsl:choose>
255        <xsl:when test="$previous">
256          <xsl:text>obsoleted by</xsl:text>
257          <xsl:for-each select="$previous">
258            <xsl:sort select="translate(dc:date,'-','')"/>
259            <xsl:if test="position()=last()">
260              <xsl:text> </xsl:text>
261              <xsl:call-template name="base-name">
262                <xsl:with-param name="s" select="@rdf:about"/>
263              </xsl:call-template>
264            </xsl:if>
265          </xsl:for-each>
266        </xsl:when>
267        <xsl:otherwise>
268          <xsl:text>ok</xsl:text>
269        </xsl:otherwise>
270      </xsl:choose>
271    </xsl:when>
272    <xsl:otherwise>
273      <xsl:text>document unknown</xsl:text>
274    </xsl:otherwise>
275  </xsl:choose>
276  <xsl:text>&#10;</xsl:text>       
277</xsl:template>
278
279</xsl:transform>
Note: See TracBrowser for help on using the repository browser.