-
Notifications
You must be signed in to change notification settings - Fork 0
/
w3c-rdf-to-bibtex.xsl
85 lines (73 loc) · 3.2 KB
/
w3c-rdf-to-bibtex.xsl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:contact="http://www.w3.org/2000/10/swap/pim/contact#"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:doc="http://www.w3.org/2000/10/swap/pim/doc#"
xmlns:mat="http://www.w3.org/2002/05/matrix/vocab#"
xmlns:org="http://www.w3.org/2001/04/roadmap/org#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rec="http://www.w3.org/2001/02pd/rec54#"
xmlns:exsl="http://exslt.org/common"
version="1.0">
<xsl:output method="text" encoding="iso-8859-1"/>
<xsl:preserve-space elements="rec:REC"/>
<xsl:template match="rdf:RDF">
<xsl:apply-templates select="rec:REC"/>
</xsl:template>
<xsl:template match="rec:REC">
@TechReport{<xsl:apply-templates mode="bibtex-label" select="."/>,
author = {<xsl:apply-templates select="rec:editor[1]"/><xsl:for-each select="rec:editor[position() > 1]"> and <xsl:apply-templates select="."/></xsl:for-each>},
title = {{<xsl:apply-templates select="dc:title"/>}},
note = {\url{<xsl:value-of select="@rdf:about"/>}. Latest version available at \url{<xsl:value-of select="doc:versionOf/@rdf:resource"/>}},
year = {<xsl:apply-templates mode="bibtex-year" select="dc:date"/>},
month = <xsl:apply-templates mode="bibtex-month" select="dc:date"/>,
bibsource = "http://www.w3.org/2002/01/tr-automation/tr.rdf",
type = "Recommendation",
institution = "W3C",
}
</xsl:template>
<xsl:template match="rec:editor"><xsl:value-of select="contact:fullName"/></xsl:template>
<xsl:template match="*" mode="bibtex-label">
<xsl:variable name="subject-uri" select="@rdf:about"/>
<xsl:variable name="subject-uri-clean">
<xsl:choose>
<xsl:when test="substring($subject-uri, string-length($subject-uri), 1) = '/'">
<xsl:value-of select="substring($subject-uri, 1, string-length($subject-uri) - 1)"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$subject-uri"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="subject-id" select="substring-after($subject-uri-clean, '-')"/>
<xsl:variable name="subject" select="substring($subject-id, 1, string-length($subject-id) - 9)"/>
<xsl:text>W3C:</xsl:text>
<xsl:value-of select="$subject"/>
<xsl:text>:</xsl:text>
<xsl:apply-templates select="dc:date" mode="bibtex-year"/>
</xsl:template>
<xsl:template match="dc:date" mode="bibtex-year"><xsl:value-of select="substring-before(text(), '-')"/></xsl:template>
<xsl:template match="dc:title">
<xsl:variable name="raw-title" select="."/>
<xsl:value-of select="translate($raw-title, '™', '')"/>
</xsl:template>
<xsl:template match="dc:date" mode="bibtex-month">
<xsl:variable name="month" select="number(substring-before(substring-after(text(),'-'),'-'))"/>
<xsl:variable name="monthNames">
<m>jan</m>
<m>feb</m>
<m>mar</m>
<m>apr</m>
<m>may</m>
<m>jun</m>
<m>jul</m>
<m>aug</m>
<m>sep</m>
<m>oct</m>
<m>nov</m>
<m>dec</m>
</xsl:variable>
<xsl:value-of select="exsl:node-set($monthNames)/m[$month]/text()"/>
</xsl:template>
</xsl:stylesheet>