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"/>
5 <!-- $Id: rfcxmlindex2bibtex.xslt,v 1.7 2004/12/10 22:47:36 bless Exp $ -->
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/_/\\_/'
13 java org.apache.xalan.xslt.Process -in rfc-index.xml -xsl rfcxmlindex2bibtex.xslt -out - | sed 's/_/\\_/'
16 <!-- customizable variables -->
18 <xsl:variable name="entrytype">
19 <xsl:text>@misc</xsl:text>
22 <xsl:variable name="rfcname">
23 <xsl:text>RFC</xsl:text>
26 <xsl:variable name="urlrfcretrieval">
27 <xsl:text>http://www.ietf.org/rfc/</xsl:text>
30 <xsl:variable name="obsoletedby">
31 <xsl:text>Obsoleted by </xsl:text>
34 <xsl:variable name="updatedby">
35 <xsl:text>Updated by </xsl:text>
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>
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>
58 <!-- internal variables -->
60 <xsl:variable name="newline">
65 <xsl:variable name="escapesyms">
66 <xsl:text>_</xsl:text>
69 <!-- template matches -->
71 <xsl:template match="/">
72 <xsl:apply-templates select="rfcidx:rfc-index"/>
75 <xsl:template match="rfcidx:rfc-index">
76 <xsl:apply-templates select="rfcidx:rfc-entry"/>
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">
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>
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">
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>
108 <xsl:value-of select="rfcidx:current-status"/>
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) > 0">
119 <xsl:text> note="</xsl:text>
121 <xsl:apply-templates select="rfcidx:obsoleted-by"/>
122 <xsl:if test="count(rfcidx:updated-by) > 0">
124 <xsl:when test="count(rfcidx:obsoleted-by) > 0">
125 <xsl:text>, </xsl:text><xsl:value-of select="translate(substring($updatedby,1,1),'ABCDEFGHIJKMLNOPQRSTUVWXYZ','abcdefghijkmlnopqrstuvwxyz')"/><xsl:value-of select="substring($updatedby,2)"/>
127 <xsl:otherwise><xsl:value-of select="$updatedby"/></xsl:otherwise>
129 <xsl:apply-templates select="rfcidx:updated-by"/>
131 <xsl:if test="count(rfcidx:obsoleted-by|rfcidx:updated-by) > 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"/>
138 <xsl:template match="rfcidx:title" mode="plain">
139 <xsl:text>title="{</xsl:text><xsl:value-of select="."/><xsl:text>}"</xsl:text>
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">
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>
154 <xsl:value-of select="$originaltitle"/>
158 <xsl:value-of select="$return"/>
159 <xsl:text>}"</xsl:text>
163 <!-- replaces escapechar with \escapechar -->
164 <xsl:template name="escapechars">
165 <xsl:param name="inputstr"/>
166 <xsl:variable name="first">
168 <xsl:when test="contains($inputstr, $escapesyms)">
169 <xsl:value-of select="substring-before($inputstr, $escapesyms)"/>
172 <xsl:value-of select="$inputstr"/>
176 <xsl:variable name="middle">
178 <xsl:when test="contains($inputstr, $escapesyms)">
179 <xsl:text>\</xsl:text><xsl:value-of select="$escapesyms"/>
182 <xsl:text></xsl:text>
186 <xsl:variable name="last">
188 <xsl:when test="contains($inputstr, $escapesyms)">
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>
196 <xsl:value-of select="substring-after($inputstr, $escapesyms)"/>
201 <xsl:text></xsl:text>
205 <xsl:value-of select="concat($first, $middle, $last)"/>
208 <xsl:template match="rfcidx:date/rfcidx:day">
209 <xsl:text>day="</xsl:text><xsl:value-of select="number(.)"/>",
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) > 1">s</xsl:if><xsl:text> </xsl:text>
215 <xsl:for-each select="rfcidx:doc-id">
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>
223 <xsl:template match="rfcidx:updated-by">
224 <xsl:text>RFC</xsl:text><xsl:if test="count(rfcidx:doc-id) > 1">s</xsl:if><xsl:text> </xsl:text>
225 <xsl:for-each select="rfcidx:doc-id">
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>