]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/xsl/locDoc2xml.xsl
Initial selfcheck styling enhancements
[working/Evergreen.git] / Open-ILS / xsl / locDoc2xml.xsl
1 <!--
2
3 Copyright (C) 2008 Equinox Software, Inc.
4 Mike Rylander <miker@esilibrary.com>
5
6 This program is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA
19
20 -->
21
22
23 <!--
24
25 This XSLT will take the MARC21 Concise Format for Bibliographic Data
26 documentation maintained by the Library of Congress and turn it into an XML
27 document for use by Evergreen (and others, if you so desire, under the terms
28 of the GPL).  The LoC docs are available from:
29
30  http://www.loc.gov/marc/bibliographic/
31
32 The format of the output XML is similar to that produced sometime during
33 2005 by Ed Summers and shared at textualize.com.  That site was not available
34 at the time of this XSLT's creation, and thus this exists.
35
36 Please report any problems to Mike Rylander at <miker@esilibrary.com>.
37
38 Here's an easy way to use this:
39
40 curl -o - http://www.loc.gov/marc/bibliographic/ecbd{ldrd,cntr,007s,008s,numb,clas,main,tils,impr,phys,sers,not1,not2,subj,adde,link,srae,hold}.html | \
41  tidy -asxml -n -q -utf8 | \
42  xsltproc -\-html -\-novalid locDoc2xml.xsl - | \
43  xmllint -\-format -\-noblanks - > marcedit-tooltips.xml
44
45 -->
46
47
48 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
49     <xsl:output omit-xml-declaration="yes" method="xml" encoding="UTF-8" media-type="text/plain" />
50
51     <xsl:template match="/">
52     <fields>
53         <xsl:for-each select="//a[substring(@href,1,5)='#mrcb']">
54             <xsl:call-template name="field">
55                 <xsl:with-param name="datafieldLabel" select="substring-after(@href,'#')"/>
56             </xsl:call-template>
57         </xsl:for-each>
58     </fields>
59     </xsl:template>
60
61     <xsl:template name="field">
62         <xsl:param name="datafieldLabel"/>
63         <xsl:variable name="locatorAnchor" select="//a[@name=$datafieldLabel]"/>
64
65         <xsl:variable name="tagValue" select="substring-before($locatorAnchor, ' - ')"/>
66         <xsl:if test="$tagValue != ''">
67
68             <xsl:variable name="nameStart" select="substring-after($locatorAnchor, ' - ')"/>
69
70             <xsl:variable name="nameValue" select="substring-before($nameStart, '(')"/>
71
72             <xsl:variable name="repeatable" select="substring-after($nameStart, '(')"/>
73             <xsl:variable name="description" select="$locatorAnchor/parent::node()/following-sibling::node()/descendant-or-self::*"/>
74
75             <field>
76                 <xsl:attribute name="tag">
77                     <xsl:value-of select="$tagValue"/>
78                 </xsl:attribute>
79                 <xsl:attribute name="repeatable">
80                     <xsl:choose>
81                         <xsl:when test="substring($repeatable,1,1)='R'">
82                             <xsl:text>true</xsl:text>
83                         </xsl:when>
84                         <xsl:otherwise>
85                             <xsl:text>false</xsl:text>
86                         </xsl:otherwise>
87                     </xsl:choose>
88                 </xsl:attribute>
89
90                 <name>
91                     <xsl:value-of select="normalize-space($nameValue)"/>
92                 </name>
93
94                 <description>
95                     <xsl:value-of select="normalize-space($description)"/>
96                 </description>
97
98                 <xsl:call-template name="indicators">
99                     <xsl:with-param name="indUL" select="$locatorAnchor/parent::node()/following-sibling::h3[.='Indicators'][1]/following-sibling::ul[1]"/>
100                 </xsl:call-template>
101
102                 <xsl:if test="substring($tagValue,1,2) != '00'">
103                     <xsl:call-template name="subfields">
104                         <xsl:with-param name="sfUL" select="$locatorAnchor/parent::node()/following-sibling::h3[.='Subfield Codes'][1]/following-sibling::ul[1]"/>
105                     </xsl:call-template>
106                 </xsl:if>
107
108             </field>
109
110         </xsl:if>
111     </xsl:template>
112
113     <xsl:template name="indicators">
114         <xsl:param name="indUL"/>
115         <xsl:for-each select="$indUL/li">
116             <xsl:if test="string-length(substring-after(.,' - Undefi')) = 0">
117
118                 <xsl:variable name="indPos">
119                     <xsl:choose>
120                         <xsl:when test="starts-with(.,'First')">
121                             <xsl:text>1</xsl:text>
122                         </xsl:when>
123                         <xsl:otherwise>
124                             <xsl:text>2</xsl:text>
125                         </xsl:otherwise>
126                     </xsl:choose>
127                 </xsl:variable>
128
129                 <xsl:for-each select="./ul/li">
130                     <indicator>
131                         <xsl:attribute name="position">
132                             <xsl:value-of select="$indPos"/>
133                         </xsl:attribute>
134
135                         <xsl:attribute name="value">
136                             <xsl:value-of select="substring-before(.,' - ')"/>
137                         </xsl:attribute>
138
139                         <description>
140                             <xsl:value-of select="normalize-space(substring-after(.,' - '))"/>
141                         </description>
142                     </indicator>
143                 </xsl:for-each>
144             </xsl:if>
145         </xsl:for-each>
146     </xsl:template>
147
148     <xsl:template name="subfields">
149         <xsl:param name="sfUL"/>
150         <xsl:for-each select="$sfUL/li">
151             <xsl:variable name="sfCode" select="substring-before(., ' - ')"/>
152             <xsl:variable name="descStart" select="substring-after(., ' - ')"/>
153             <xsl:variable name="descValue" select="substring-before($descStart, '(')"/>
154             <xsl:variable name="sfRepeatable" select="substring-after(., '(')"/>
155
156             <subfield>
157                 <xsl:attribute name="code">
158                     <xsl:value-of select="substring($sfCode,2,1)"/>
159                 </xsl:attribute>
160
161                 <xsl:attribute name="repeatable">
162                     <xsl:choose>
163                         <xsl:when test="substring($sfRepeatable,1,1)='R'">
164                             <xsl:text>true</xsl:text>
165                         </xsl:when>
166                         <xsl:otherwise>
167                             <xsl:text>false</xsl:text>
168                         </xsl:otherwise>
169                     </xsl:choose>
170                 </xsl:attribute>
171
172                 <description>
173                     <xsl:value-of select="normalize-space($descValue)"/>
174                 </description>
175             </subfield>
176         </xsl:for-each>
177     </xsl:template>
178
179 </xsl:stylesheet>
180