3 Copyright (C) 2008 Equinox Software, Inc.
4 Mike Rylander <miker@esilibrary.com>
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.
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.
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
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:
30 http://www.loc.gov/marc/bibliographic/
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.
36 Please report any problems to Mike Rylander at <miker@esilibrary.com>.
38 Here's an easy way to use this:
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
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" />
51 <xsl:template match="/">
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,'#')"/>
61 <xsl:template name="field">
62 <xsl:param name="datafieldLabel"/>
63 <xsl:variable name="locatorAnchor" select="//a[@name=$datafieldLabel]"/>
65 <xsl:variable name="tagValue" select="substring-before($locatorAnchor, ' - ')"/>
66 <xsl:if test="$tagValue != ''">
68 <xsl:variable name="nameStart" select="substring-after($locatorAnchor, ' - ')"/>
70 <xsl:variable name="nameValue" select="substring-before($nameStart, '(')"/>
72 <xsl:variable name="repeatable" select="substring-after($nameStart, '(')"/>
73 <xsl:variable name="description" select="$locatorAnchor/parent::node()/following-sibling::node()/descendant-or-self::*"/>
76 <xsl:attribute name="tag">
77 <xsl:value-of select="$tagValue"/>
79 <xsl:attribute name="repeatable">
81 <xsl:when test="substring($repeatable,1,1)='R'">
82 <xsl:text>true</xsl:text>
85 <xsl:text>false</xsl:text>
91 <xsl:value-of select="normalize-space($nameValue)"/>
95 <xsl:value-of select="normalize-space($description)"/>
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]"/>
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]"/>
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">
118 <xsl:variable name="indPos">
120 <xsl:when test="starts-with(.,'First')">
121 <xsl:text>1</xsl:text>
124 <xsl:text>2</xsl:text>
129 <xsl:for-each select="./ul/li">
131 <xsl:attribute name="position">
132 <xsl:value-of select="$indPos"/>
135 <xsl:attribute name="value">
136 <xsl:value-of select="substring-before(.,' - ')"/>
140 <xsl:value-of select="normalize-space(substring-after(.,' - '))"/>
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(., '(')"/>
157 <xsl:attribute name="code">
158 <xsl:value-of select="substring($sfCode,2,1)"/>
161 <xsl:attribute name="repeatable">
163 <xsl:when test="substring($sfRepeatable,1,1)='R'">
164 <xsl:text>true</xsl:text>
167 <xsl:text>false</xsl:text>
173 <xsl:value-of select="normalize-space($descValue)"/>