summaryrefslogtreecommitdiffstats
path: root/xslt/referencer2tellico.xsl
blob: 5bb90bede48cf8d078e68f05a322e7957d410a99 (plain)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                xmlns="http://periapsis.org/tellico/"
                xmlns:str="http://exslt.org/strings"
                xmlns:exsl="http://exslt.org/common"
                extension-element-prefixes="str exsl"
                version="1.0">

<!--
   ===================================================================
   Tellico XSLT file - used for importing data Referencer

   Copyright (C) 2007 Robby Stephenson - robby@periapsis.org

   This XSLT stylesheet is designed to be used with the 'Tellico'
   application, which can be found at http://www.periapsis.org/tellico/

   ===================================================================
-->

<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"
            doctype-public="-//Robby Stephenson/DTD Tellico V10.0//EN"
            doctype-system="http://periapsis.org/tellico/dtd/v10/tellico.dtd"/>

<xsl:key name="tags" match="/library/taglist/tag" use="uid"/>

<xsl:template match="/">
 <tellico syntaxVersion="10">
  <collection title="Referencer Import" type="5">
   <fields>
    <field name="_default"/>
   </fields>
   <xsl:apply-templates select="library/doclist/doc"/>
  </collection>
 </tellico>
</xsl:template>

<xsl:template match="doc">
 <entry>

  <title>
   <xsl:value-of select="bib_title"/>
  </title>

  <entry-type>
   <xsl:value-of select="translate(bib_type, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
                                             'abcdefghijklmnopqrstuvwxyz')"/>
  </entry-type>

  <bibtex-key>
   <xsl:value-of select="key"/>
  </bibtex-key>

  <year>
   <xsl:value-of select="bib_year"/>
  </year>

  <doi>
   <xsl:value-of select="bib_doi"/>
  </doi>

  <pages>
   <xsl:value-of select="bib_pages"/>
  </pages>

  <journal>
   <xsl:value-of select="bib_journal"/>
  </journal>

  <number>
   <xsl:value-of select="bib_number"/>
  </number>

  <volume>
   <xsl:value-of select="bib_volume"/>
  </volume>

  <url>
   <xsl:value-of select="filename"/>
  </url>

  <authors>
   <xsl:for-each select="str:tokenize(bib_authors, ',/;')">
    <xsl:call-template name="author_split">
     <xsl:with-param name="value" select="."/>
    </xsl:call-template>
   </xsl:for-each>
  </authors>

  <keywords>
   <xsl:for-each select="tagged">
    <keyword i18n="true">
     <xsl:value-of select="key('tags', .)/name"/>
    </keyword>
   </xsl:for-each>
  </keywords>

</entry>

</xsl:template>

<xsl:template name="author_split">
 <xsl:param name="value"/>
 <xsl:if test="string-length($value) &gt; 0">
  <xsl:variable name="before" select="substring-before($value, ' and ')"/>
  <author>
   <xsl:if test="string-length($before) &gt; 0">
    <xsl:value-of select="normalize-space($before)"/>
   </xsl:if>
   <xsl:if test="string-length($before) = 0">
    <xsl:value-of select="normalize-space($value)"/>
   </xsl:if>
  </author>
  <xsl:call-template name="author_split">
   <xsl:with-param name="value" select="substring-after($value, ' and ')"/>
  </xsl:call-template>
 </xsl:if>
</xsl:template>

</xsl:stylesheet>