etc/post-mirror.d/worldofspectrum: Maintain an unzipped tree in parallel.
[mirror-admin] / lib / rfcxmlindex2bibtex.xslt
CommitLineData
840a2c3a
MW
1<xsl:transform xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
2 xmlns:rfcidx="http://www.rfc-editor.org/rfc-index" >
3<xsl:output method="text"/>
4
5<!-- $Id: rfcxmlindex2bibtex.xslt,v 1.7 2004/12/10 22:47:36 bless Exp $ -->
6
7<!-- rfcxmlindex2bibtex.xslt written by Roland Bless -->
8<!-- This is my very first xslt script, so please don't blame me for bad coding style -->
9<!-- Get rfc-index in xml format from ftp://ftp.isi.edu/in-notes/rfc-index.xml
10 then translate it to bibtex format by invoking e.g.:
11 xsltproc rfcxmlindex2bibtex rfc-index.xml | sed 's/_/\\_/'
12 or
13 java org.apache.xalan.xslt.Process -in rfc-index.xml -xsl rfcxmlindex2bibtex.xslt -out - | sed 's/_/\\_/'
14 -->
15
16<!-- customizable variables -->
17
18<xsl:variable name="entrytype">
19 <xsl:text>@misc</xsl:text>
20</xsl:variable>
21
22<xsl:variable name="rfcname">
23<xsl:text>RFC</xsl:text>
24</xsl:variable>
25
26<xsl:variable name="urlrfcretrieval">
27<xsl:text>http://www.ietf.org/rfc/</xsl:text>
28</xsl:variable>
29
30<xsl:variable name="obsoletedby">
31<xsl:text>Obsoleted by </xsl:text>
32</xsl:variable>
33
34<xsl:variable name="updatedby">
35<xsl:text>Updated by </xsl:text>
36</xsl:variable>
37
38<xsl:variable name="statFS">STANDARD</xsl:variable>
39<xsl:variable name="statDS">DRAFT STANDARD</xsl:variable>
40<xsl:variable name="statPS">PROPOSED STANDARD</xsl:variable>
41<xsl:variable name="statU">UNKNOWN</xsl:variable>
42<xsl:variable name="statBCP">BEST CURRENT PRACTICE</xsl:variable>
43<xsl:variable name="statFYI">FOR YOUR INFORMATION</xsl:variable>
44<xsl:variable name="statEXP">EXPERIMENTAL</xsl:variable>
45<xsl:variable name="statH">HISTORIC</xsl:variable>
46<xsl:variable name="statI">INFORMATIONAL</xsl:variable>
47
48<xsl:variable name="lstatFS">Standard</xsl:variable>
49<xsl:variable name="lstatDS">Draft Standard</xsl:variable>
50<xsl:variable name="lstatPS">Proposed Standard</xsl:variable>
51<xsl:variable name="lstatU">Unknown</xsl:variable>
52<xsl:variable name="lstatBCP">Best Current Practice</xsl:variable>
53<xsl:variable name="lstatFYI">For Your Information</xsl:variable>
54<xsl:variable name="lstatEXP">Experimental</xsl:variable>
55<xsl:variable name="lstatH">Historic</xsl:variable>
56<xsl:variable name="lstatI">Informational</xsl:variable>
57
58<!-- internal variables -->
59
60<xsl:variable name="newline">
61<xsl:text>
62</xsl:text>
63</xsl:variable>
64
65<xsl:variable name="escapesyms">
66 <xsl:text>_</xsl:text>
67</xsl:variable>
68
69<!-- template matches -->
70
71<xsl:template match="/">
72 <xsl:apply-templates select="rfcidx:rfc-index"/>
73</xsl:template>
74
75<xsl:template match="rfcidx:rfc-index">
76 <xsl:apply-templates select="rfcidx:rfc-entry"/>
77</xsl:template>
78
79<xsl:template match="rfcidx:rfc-entry">
80 <xsl:value-of select="$entrytype" /><xsl:text>{rfc</xsl:text>
81 <xsl:variable name="rfcno" select="number(substring-after(rfcidx:doc-id/text(),$rfcname))"/>
82 <xsl:value-of select="$rfcno"/>,
83 <xsl:text>author="</xsl:text>
84 <xsl:value-of select="rfcidx:author/rfcidx:name"/>
85 <xsl:for-each select="rfcidx:author/rfcidx:name">
86 <xsl:choose>
87 <xsl:when test="position()=1"><xsl:value-of select="rfcidx:author/rfcidx:name"/></xsl:when>
88 <xsl:when test="position()>1"><xsl:text> and </xsl:text><xsl:value-of select="."/></xsl:when>
89 </xsl:choose>
90 </xsl:for-each>",
91 <xsl:apply-templates select="rfcidx:title" mode="plain"/>,
92 <xsl:text>series="Request for Comments"</xsl:text>,
93 <xsl:text>number="</xsl:text><xsl:value-of select="$rfcno"/>",
94 <xsl:text>howpublished="RFC </xsl:text><xsl:value-of select="$rfcno"/>
95 <xsl:variable name="rstatus" select="rfcidx:current-status"/>
96 <xsl:variable name="cstatus">
97 <xsl:choose>
98 <xsl:when test="$rstatus=$statFS" ><xsl:value-of select="$lstatFS"/></xsl:when>
99 <xsl:when test="$rstatus=$statDS" ><xsl:value-of select="$lstatDS"/></xsl:when>
100 <xsl:when test="$rstatus=$statPS" ><xsl:value-of select="$lstatPS"/></xsl:when>
101 <xsl:when test="$rstatus=$statU" ><xsl:value-of select="$lstatU"/></xsl:when>
102 <xsl:when test="$rstatus=$statBCP"><xsl:value-of select="$lstatBCP"/></xsl:when>
103 <xsl:when test="$rstatus=$statFYI"><xsl:value-of select="$lstatFYI"/></xsl:when>
104 <xsl:when test="$rstatus=$statEXP"><xsl:value-of select="$lstatEXP"/></xsl:when>
105 <xsl:when test="$rstatus=$statH" ><xsl:value-of select="$lstatH"/></xsl:when>
106 <xsl:when test="$rstatus=$statI"><xsl:value-of select="$lstatI"/></xsl:when>
107 <xsl:otherwise>
108 <xsl:value-of select="rfcidx:current-status"/>
109 </xsl:otherwise>
110 </xsl:choose>
111 </xsl:variable>
112 <xsl:if test="not(rfcidx:current-status='UNKNOWN')"> (<xsl:value-of select="$cstatus"/>)</xsl:if>",
113 <xsl:text>publisher="IETF"</xsl:text>,
114 <xsl:text>organisation="Internet Engineering Task Force"</xsl:text>,
115 <xsl:text>year=</xsl:text><xsl:value-of select="rfcidx:date/rfcidx:year"/>,
116 <xsl:text>month=</xsl:text><xsl:value-of select="translate(substring(rfcidx:date/rfcidx:month,1,3),'ABCDEFGHIJKMLNOPQRSTUVWXYZ','abcdefghijkmlnopqrstuvwxyz')"/>,
117 <xsl:apply-templates select="rfcidx:date/rfcidx:day"/>
118 <xsl:if test="count(rfcidx:obsoleted-by|rfcidx:updated-by) &gt; 0">
119 <xsl:text> note="</xsl:text>
120 </xsl:if>
121 <xsl:apply-templates select="rfcidx:obsoleted-by"/>
122 <xsl:if test="count(rfcidx:updated-by) &gt; 0">
123 <xsl:choose>
124 <xsl:when test="count(rfcidx:obsoleted-by) &gt; 0">
125 <xsl:text>, </xsl:text><xsl:value-of select="translate(substring($updatedby,1,1),'ABCDEFGHIJKMLNOPQRSTUVWXYZ','abcdefghijkmlnopqrstuvwxyz')"/><xsl:value-of select="substring($updatedby,2)"/>
126 </xsl:when>
127 <xsl:otherwise><xsl:value-of select="$updatedby"/></xsl:otherwise>
128 </xsl:choose>
129 <xsl:apply-templates select="rfcidx:updated-by"/>
130 </xsl:if>
131 <xsl:if test="count(rfcidx:obsoleted-by|rfcidx:updated-by) &gt; 0"><xsl:text>",</xsl:text><xsl:value-of select="$newline"/></xsl:if>
132 <xsl:text> url="</xsl:text><xsl:value-of select="$urlrfcretrieval"/><xsl:text>rfc</xsl:text><xsl:value-of select="$rfcno"/>.txt",
133<xsl:text>}</xsl:text><xsl:value-of select="$newline"/>
134<xsl:value-of select="$newline"/>
135</xsl:template>
136
137
138<xsl:template match="rfcidx:title" mode="plain">
139 <xsl:text>title="{</xsl:text><xsl:value-of select="."/><xsl:text>}"</xsl:text>
140</xsl:template>
141
142<!-- replaces _ with \_ , but it is very slow -> better use sed -->
143<xsl:template match="rfcidx:title" mode="replace">
144 <xsl:text>title="{</xsl:text>
145 <xsl:variable name="originaltitle" select="."/>
146 <xsl:variable name="return">
147 <xsl:choose>
148 <xsl:when test="contains($originaltitle,$escapesyms)">
149 <xsl:call-template name="escapechars">
150 <xsl:with-param name="inputstr"><xsl:value-of select="$originaltitle"/></xsl:with-param>
151 </xsl:call-template>
152 </xsl:when>
153 <xsl:otherwise>
154 <xsl:value-of select="$originaltitle"/>
155 </xsl:otherwise>
156 </xsl:choose>
157 </xsl:variable>
158 <xsl:value-of select="$return"/>
159 <xsl:text>}"</xsl:text>
160</xsl:template>
161
162
163<!-- replaces escapechar with \escapechar -->
164<xsl:template name="escapechars">
165 <xsl:param name="inputstr"/>
166 <xsl:variable name="first">
167 <xsl:choose>
168 <xsl:when test="contains($inputstr, $escapesyms)">
169 <xsl:value-of select="substring-before($inputstr, $escapesyms)"/>
170 </xsl:when>
171 <xsl:otherwise>
172 <xsl:value-of select="$inputstr"/>
173 </xsl:otherwise>
174 </xsl:choose>
175 </xsl:variable>
176 <xsl:variable name="middle">
177 <xsl:choose>
178 <xsl:when test="contains($inputstr, $escapesyms)">
179 <xsl:text>\</xsl:text><xsl:value-of select="$escapesyms"/>
180 </xsl:when>
181 <xsl:otherwise>
182 <xsl:text></xsl:text>
183 </xsl:otherwise>
184 </xsl:choose>
185 </xsl:variable>
186 <xsl:variable name="last">
187 <xsl:choose>
188 <xsl:when test="contains($inputstr, $escapesyms)">
189 <xsl:choose>
190 <xsl:when test="contains(substring-after($inputstr, $escapesyms), $escapesyms)">
191 <xsl:call-template name="escapechars">
192 <xsl:with-param name="inputstr"><xsl:value-of select="substring-after($inputstr, $escapesyms)"/></xsl:with-param>
193 </xsl:call-template>
194 </xsl:when>
195 <xsl:otherwise>
196 <xsl:value-of select="substring-after($inputstr, $escapesyms)"/>
197 </xsl:otherwise>
198 </xsl:choose>
199 </xsl:when>
200 <xsl:otherwise>
201 <xsl:text></xsl:text>
202 </xsl:otherwise>
203 </xsl:choose>
204 </xsl:variable>
205 <xsl:value-of select="concat($first, $middle, $last)"/>
206</xsl:template>
207
208<xsl:template match="rfcidx:date/rfcidx:day">
209<xsl:text>day="</xsl:text><xsl:value-of select="number(.)"/>",
210</xsl:template>
211
212<xsl:template match="rfcidx:obsoleted-by">
213 <xsl:value-of select="$obsoletedby"/>
214 <xsl:text>RFC</xsl:text><xsl:if test="count(rfcidx:doc-id) &gt; 1">s</xsl:if><xsl:text> </xsl:text>
215 <xsl:for-each select="rfcidx:doc-id">
216 <xsl:choose>
217 <xsl:when test="position()=1"><xsl:value-of select="number(substring-after(text(),$rfcname))"/></xsl:when>
218 <xsl:when test="position()>1"><xsl:text>, </xsl:text><xsl:value-of select="number(substring-after(text(),$rfcname))"/></xsl:when>
219 </xsl:choose>
220 </xsl:for-each>
221</xsl:template>
222
223<xsl:template match="rfcidx:updated-by">
224 <xsl:text>RFC</xsl:text><xsl:if test="count(rfcidx:doc-id) &gt; 1">s</xsl:if><xsl:text> </xsl:text>
225 <xsl:for-each select="rfcidx:doc-id">
226 <xsl:choose>
227 <xsl:when test="position()=1"><xsl:value-of select="number(substring-after(text(),$rfcname))"/></xsl:when>
228 <xsl:when test="position()>1"><xsl:text>, </xsl:text><xsl:value-of select="number(substring-after(text(),$rfcname))"/></xsl:when>
229 </xsl:choose>
230 </xsl:for-each>
231</xsl:template>
232
233</xsl:transform>