Skip to content

Commit a1f10e0

Browse files
authored
Merge pull request #109 from lcnetdev/issue-98-local-use
Add "localfields" parameter.
2 parents b714bfe + fa6b14d commit a1f10e0

4 files changed

Lines changed: 97 additions & 13 deletions

File tree

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ The converter supports four optional parameters:
6363
`http://id.loc.gov/vocabulary/organizations/dlc`. This will be empty
6464
by default, resulting in no source property being defined.
6565

66+
- `localfield` - if true, process fields that are local to the Library
67+
of Congress records. Right now, the only field affected is the 859.
68+
6669
- `pGenerationDatestamp` - a value to be used as the datestamp for the
6770
bf:generationProcess property for the Work AdminMetadata. Defaults
6871
to the current date/time if the EXSLT `date:date-time()` function is

test/ConvSpec-841-887.xspec

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,10 @@
1010
stylesheet="../xsl/marc2bibframe2.xsl"
1111
xslt-version="1.0">
1212

13-
<x:scenario label="856/859 - ELECTRONIC LOCATION AND ACCESS">
13+
<x:scenario label="856 - ELECTRONIC LOCATION AND ACCESS">
1414
<x:scenario label="If ind1 = #, 0, 1, or 8">
1515
<x:context href="data/ConvSpec-841-887/marc.xml"/>
16-
<x:expect label="If Instance is Electronic, 856 creates an Item of the Instance" test="count(//bf:Instance[@rdf:about='http://example.org/2#Instance']/bf:hasItem/bf:Item) = 2"/>
16+
<x:expect label="If Instance is Electronic, 856 creates an Item of the Instance" test="//bf:Instance[@rdf:about='http://example.org/2#Instance']/bf:hasItem[1]/bf:Item/@rdf:about = 'http://example.org/2#Item856-5'"/>
1717
<x:expect label="...otherwise, 856 creates a new Instance of the Work" test="count(//bf:Work[@rdf:about='http://example.org/1#Work']/bf:hasInstance/bf:Instance) = 1"/>
1818
<x:expect label="...with an Item" test="count(//bf:Work[@rdf:about='http://example.org/1#Work']/bf:hasInstance/bf:Instance/bf:hasItem/bf:Item) = 1"/>
1919
</x:scenario>
@@ -27,10 +27,11 @@
2727
<x:expect label="...otherwise it creates a blank node with a bflc:locator property from $u" test="//bf:Work[@rdf:about='http://example.org/1#Work']/bf:hasInstance[1]/bf:Instance/bf:hasItem/bf:Item/bf:electronicLocator/rdfs:Resource/bflc:locator/@rdf:resource = 'http://www.ref.oclc.org:2000'"/>
2828
<x:expect label="...with notes generated from $z/y/3" test="//bf:Instance[@rdf:about='http://example.org/1#Instance']/bf:supplementaryContent/rdfs:Resource/bf:note[1]/bf:Note/rdfs:label = 'Finding aid'"/>
2929
</x:scenario>
30-
<x:scenario label="859">
31-
<x:context href="data/ConvSpec-841-887/marc.xml"/>
32-
<x:expect label="859 processed same as 856" test="//bf:Instance[@rdf:about='http://example.org/2#Instance']/bf:hasItem[2]/bf:Item/bf:electronicLocator/@rdf:resource = 'http://example.org/fakebook2.html'"/>
33-
</x:scenario>
30+
<!-- to test 859 conversion, uncomment this scenario and set the stylesheet parameter "localfields" -->
31+
<!-- <x:scenario label="859 (LoC local field parsed like 856)"> -->
32+
<!-- <x:context href="data/ConvSpec-841-887/marc.xml"/> -->
33+
<!-- <x:expect label="859 processed same as 856" test="//bf:Instance[@rdf:about='http://example.org/2#Instance']/bf:hasItem[2]/bf:Item/bf:electronicLocator/@rdf:resource = 'http://example.org/fakebook2.html'"/> -->
34+
<!-- </x:scenario> -->
3435
</x:scenario>
3536

3637
</x:description>

xsl/ConvSpec-841-887.xsl

Lines changed: 76 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,41 @@
1313
Conversion specs for 841-887
1414
-->
1515

16-
<xsl:template match="marc:datafield[@tag='856' or @tag='859']" mode="work">
16+
<xsl:template match="marc:datafield[@tag='856']" mode="work">
1717
<xsl:param name="recordid"/>
1818
<xsl:param name="serialization" select="'rdfxml'"/>
19+
<xsl:apply-templates select="." mode="work856">
20+
<xsl:with-param name="recordid" select="$recordid"/>
21+
<xsl:with-param name="serialization" select="$serialization"/>
22+
<xsl:with-param name="pTagOrd" select="position()"/>
23+
</xsl:apply-templates>
24+
</xsl:template>
25+
26+
<!-- 859 is a local field at LoC -->
27+
<xsl:template match="marc:datafield[@tag='859']" mode="work">
28+
<xsl:param name="recordid"/>
29+
<xsl:param name="serialization" select="'rdfxml'"/>
30+
<xsl:if test="$localfields">
31+
<xsl:apply-templates select="." mode="work856">
32+
<xsl:with-param name="recordid" select="$recordid"/>
33+
<xsl:with-param name="serialization" select="$serialization"/>
34+
<xsl:with-param name="pTagOrd" select="position()"/>
35+
</xsl:apply-templates>
36+
</xsl:if>
37+
</xsl:template>
38+
39+
<xsl:template match="marc:datafield" mode="work856">
40+
<xsl:param name="recordid"/>
41+
<xsl:param name="serialization" select="'rdfxml'"/>
42+
<xsl:param name="pTagOrd" select="position()"/>
1943
<!-- If ind2 is #, 0, 1, or 8 and the Instance does not have the class of Electronic, create a new Instance -->
2044
<xsl:if test="marc:subfield[@code='u'] and
2145
(@ind2=' ' or @ind2='0' or @ind2='1' or @ind2='8') and
2246
(substring(../marc:leader,7,1) != 'm' and
2347
substring(../marc:controlfield[@tag='008'],24,1) != 'o' and
2448
substring(../marc:controlfield[@tag='008'],24,1) != 's')">
25-
<xsl:variable name="vInstanceUri"><xsl:value-of select="$recordid"/>#Instance<xsl:value-of select="@tag"/>-<xsl:value-of select="position()"/></xsl:variable>
26-
<xsl:variable name="vItemUri"><xsl:value-of select="$recordid"/>#Item<xsl:value-of select="@tag"/>-<xsl:value-of select="position()"/></xsl:variable>
49+
<xsl:variable name="vInstanceUri"><xsl:value-of select="$recordid"/>#Instance<xsl:value-of select="@tag"/>-<xsl:value-of select="$pTagOrd"/></xsl:variable>
50+
<xsl:variable name="vItemUri"><xsl:value-of select="$recordid"/>#Item<xsl:value-of select="@tag"/>-<xsl:value-of select="$pTagOrd"/></xsl:variable>
2751
<xsl:choose>
2852
<xsl:when test="$serialization = 'rdfxml'">
2953
<bf:hasInstance>
@@ -72,7 +96,28 @@
7296
</xsl:if>
7397
</xsl:template>
7498

75-
<xsl:template match="marc:datafield[@tag='856' or @tag='859']" mode="instance">
99+
<xsl:template match="marc:datafield[@tag='856']" mode="instance">
100+
<xsl:param name="recordid"/>
101+
<xsl:param name="serialization" select="'rdfxml'"/>
102+
<xsl:apply-templates select="." mode="instance856">
103+
<xsl:with-param name="recordid" select="$recordid"/>
104+
<xsl:with-param name="serialization" select="$serialization"/>
105+
</xsl:apply-templates>
106+
</xsl:template>
107+
108+
<!-- 859 is a local field at LoC -->
109+
<xsl:template match="marc:datafield[@tag='859']" mode="instance">
110+
<xsl:param name="recordid"/>
111+
<xsl:param name="serialization" select="'rdfxml'"/>
112+
<xsl:if test="$localfields">
113+
<xsl:apply-templates select="." mode="instance856">
114+
<xsl:with-param name="recordid" select="$recordid"/>
115+
<xsl:with-param name="serialization" select="$serialization"/>
116+
</xsl:apply-templates>
117+
</xsl:if>
118+
</xsl:template>
119+
120+
<xsl:template match="marc:datafield" mode="instance856">
76121
<xsl:param name="recordid"/>
77122
<xsl:param name="serialization" select="'rdfxml'"/>
78123
<xsl:if test="marc:subfield[@code='u'] and @ind2='2'">
@@ -87,16 +132,40 @@
87132
</xsl:if>
88133
</xsl:template>
89134

90-
<xsl:template match="marc:datafield[@tag='856' or @tag='859']" mode="hasItem">
135+
<xsl:template match="marc:datafield[@tag='856']" mode="hasItem">
136+
<xsl:param name="recordid"/>
137+
<xsl:param name="serialization" select="'rdfxml'"/>
138+
<xsl:apply-templates select="." mode="hasItem856">
139+
<xsl:with-param name="recordid" select="$recordid"/>
140+
<xsl:with-param name="serialization" select="$serialization"/>
141+
<xsl:with-param name="pTagOrd" select="position()"/>
142+
</xsl:apply-templates>
143+
</xsl:template>
144+
145+
<!-- 859 is a local field at LoC -->
146+
<xsl:template match="marc:datafield[@tag='859']" mode="hasItem">
147+
<xsl:param name="recordid"/>
148+
<xsl:param name="serialization" select="'rdfxml'"/>
149+
<xsl:if test="$localfields">
150+
<xsl:apply-templates select="." mode="hasItem856">
151+
<xsl:with-param name="recordid" select="$recordid"/>
152+
<xsl:with-param name="serialization" select="$serialization"/>
153+
<xsl:with-param name="pTagOrd" select="position()"/>
154+
</xsl:apply-templates>
155+
</xsl:if>
156+
</xsl:template>
157+
158+
<xsl:template match="marc:datafield" mode="hasItem856">
91159
<xsl:param name="recordid"/>
92160
<xsl:param name="serialization" select="'rdfxml'"/>
161+
<xsl:param name="pTagOrd" select="position()"/>
93162
<!-- If ind2 is #, 0, 1, or 8 and the Instance has the class of Electronic, add an Item to the Instance -->
94163
<xsl:if test="marc:subfield[@code='u'] and
95164
(@ind2=' ' or @ind2='0' or @ind2='1' or @ind2='8') and
96165
(substring(../marc:leader,7,1) = 'm' or
97166
substring(../marc:controlfield[@tag='008'],24,1) = 'o' or
98167
substring(../marc:controlfield[@tag='008'],24,1) = 's')">
99-
<xsl:variable name="vItemUri"><xsl:value-of select="$recordid"/>#Item<xsl:value-of select="@tag"/>-<xsl:value-of select="position()"/></xsl:variable>
168+
<xsl:variable name="vItemUri"><xsl:value-of select="$recordid"/>#Item<xsl:value-of select="@tag"/>-<xsl:value-of select="$pTagOrd"/></xsl:variable>
100169
<xsl:choose>
101170
<xsl:when test="$serialization = 'rdfxml'">
102171
<bf:hasItem>
@@ -116,7 +185,7 @@
116185
</xsl:if>
117186
</xsl:template>
118187

119-
<xsl:template match="marc:datafield[@tag='856' or @tag='859']" mode="locator856">
188+
<xsl:template match="marc:datafield" mode="locator856">
120189
<xsl:param name="serialization" select="'rdfxml'"/>
121190
<xsl:param name="pProp"/>
122191
<xsl:choose>

xsl/marc2bibframe2.xsl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,17 @@
3939
<xsl:param name="idsource"/>
4040
<!-- <xsl:param name="idsource" select="'http://id.loc.gov/vocabulary/organizations/dlc'"/> -->
4141

42+
<!--
43+
Use field conversion for locally defined fields.
44+
Some fields in the conversion (e.g. 859) are locally defined by
45+
LoC for conversion. By default these fields will not be
46+
converted unless this parameter evaluates to true()
47+
To run a test of the localfields parameter, uncomment the
48+
following line, and uncomment the test in test/ConvSpec-841-887.xspec
49+
-->
50+
<!-- <xsl:param name="localfields" select="true()"/> -->
51+
<xsl:param name="localfields"/>
52+
4253
<!--
4354
datestamp for generationProcess property of Work adminMetadata
4455
Useful to override if date:date-time() extension is not

0 commit comments

Comments
 (0)