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
30 The format of the output XML is similar to that produced sometime during
31 2005 by Ed Summers and shared at textualize.com. That site was not available
32 at the time of this XSLT's creation, and thus this exists.
34 Please report any problems to Mike Rylander at <miker@esilibrary.com>.
36 Here's an easy way to use this:
38 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 | \
39 tidy -asxml -n -q -utf8 | \
40 xsltproc ‐‐html ‐‐novalid locDoc2xml.xsl - | \
41 xmllint ‐‐format ‐‐noblanks - > marcedit-tooltips.xml
46 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
47 <xsl:output omit-xml-declaration="yes" method="xml" encoding="UTF-8" media-type="text/plain" />
49 <xsl:template match="/">
51 <xsl:for-each select="//a[substring(@href,1,5)='#mrcb']">
52 <xsl:call-template name="field">
53 <xsl:with-param name="datafieldLabel" select="substring-after(@href,'#')"/>
59 <xsl:template name="field">
60 <xsl:param name="datafieldLabel"/>
61 <xsl:variable name="locatorAnchor" select="//a[@name=$datafieldLabel]"/>
63 <xsl:variable name="tagValue" select="substring-before($locatorAnchor, ' - ')"/>
64 <xsl:if test="$tagValue != ''">
66 <xsl:variable name="nameStart" select="substring-after($locatorAnchor, ' - ')"/>
68 <xsl:variable name="nameValue" select="substring-before($nameStart, '(')"/>
70 <xsl:variable name="repeatable" select="substring-after($nameStart, '(')"/>
71 <xsl:variable name="description" select="$locatorAnchor/parent::node()/following-sibling::node()/descendant-or-self::*"/>
74 <xsl:attribute name="tag">
75 <xsl:value-of select="$tagValue"/>
77 <xsl:attribute name="repeatable">
79 <xsl:when test="substring($repeatable,1,1)='R'">
80 <xsl:text>true</xsl:text>
83 <xsl:text>false</xsl:text>
89 <xsl:value-of select="normalize-space($nameValue)"/>
93 <xsl:value-of select="normalize-space($description)"/>
96 <xsl:call-template name="indicators">
97 <xsl:with-param name="indUL" select="$locatorAnchor/parent::node()/following-sibling::h3[.='Indicators'][1]/following-sibling::ul[1]"/>
100 <xsl:if test="substring($tagValue,1,2) != '00'">
101 <xsl:call-template name="subfields">
102 <xsl:with-param name="sfUL" select="$locatorAnchor/parent::node()/following-sibling::h3[.='Subfield Codes'][1]/following-sibling::ul[1]"/>
111 <xsl:template name="indicators">
112 <xsl:param name="indUL"/>
113 <xsl:for-each select="$indUL/li">
114 <xsl:if test="string-length(substring-after(.,' - Undefi')) = 0">
116 <xsl:variable name="indPos">
118 <xsl:when test="starts-with(.,'First')">
119 <xsl:text>1</xsl:text>
122 <xsl:text>2</xsl:text>
127 <xsl:for-each select="./ul/li">
129 <xsl:attribute name="position">
130 <xsl:value-of select="$indPos"/>
133 <xsl:attribute name="value">
134 <xsl:value-of select="substring-before(.,' - ')"/>
138 <xsl:value-of select="normalize-space(substring-after(.,' - '))"/>
146 <xsl:template name="subfields">
147 <xsl:param name="sfUL"/>
148 <xsl:for-each select="$sfUL/li">
149 <xsl:variable name="sfCode" select="substring-before(., ' - ')"/>
150 <xsl:variable name="descStart" select="substring-after(., ' - ')"/>
151 <xsl:variable name="descValue" select="substring-before($descStart, '(')"/>
152 <xsl:variable name="sfRepeatable" select="substring-after(., '(')"/>
155 <xsl:attribute name="code">
156 <xsl:value-of select="substring($sfCode,2,1)"/>
159 <xsl:attribute name="repeatable">
161 <xsl:when test="substring($sfRepeatable,1,1)='R'">
162 <xsl:text>true</xsl:text>
165 <xsl:text>false</xsl:text>
171 <xsl:value-of select="normalize-space($descValue)"/>