source: rfc2629xslt/check-references.xslt @ 560

Last change on this file since 560 was 308, checked in by julian.reschke@…, 11 years ago

update to latest version of rfc2629.xslt, annotate spec with intended maturity level

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