Skip to content

Commit a99dc13

Browse files
committed
Refine conversion for MARC 362.
Addresses #74.
1 parent 6b3feb8 commit a99dc13

3 files changed

Lines changed: 219 additions & 31 deletions

File tree

test/ConvSpec-3XX.xspec

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,17 @@
172172
<x:expect label="ind1=0 creates a firstIssue/lastIssue property of the Instance" test="//bf:Instance[1]/bf:firstIssue = 'Vol. 1, no. 1 (Apr. 1983)' and //bf:Instance[1]/bf:lastIssue = 'v. 1, no. 3 (June 1983)'"/>
173173
<x:expect label="ind1=1 creates a note property of the Instance with noteType 'Numbering'" test="//bf:Instance[1]/bf:note/bf:Note/bf:noteType[text()='Numbering']/parent::*/rdfs:label = '3 issues in vol. 1, ceased with 3 (1983)'"/>
174174
</x:scenario>
175+
176+
<x:scenario label="362 - edge cases">
177+
<x:context href="data/ConvSpec-3XX/marc362-edge.xml"/>
178+
<x:expect label="Unformatted dates create a note property" test="//bf:Instance[1]/bf:note[1]/bf:Note/bf:noteType[text()='Numbering']/parent::*/rdfs:label = 'Began in 1989'"/>
179+
<x:expect label="Pre-AACR2 formatting creates a note" test="//bf:Instance[1]/bf:note[2]/bf:Note/bf:noteType[text()='Numbering']/parent::*/rdfs:label = 'no. 1-3; 1975-1977.'"/>
180+
<x:expect label="Parallel statements create multiple firstIssue/lastIssue elements" test="//bf:Instance[1]/bf:firstIssue[1] = 'Vol. 62 (May 1959)' and //bf:Instance[1]/bf:firstIssue[2] = 'No. 768'"/>
181+
<x:expect label="Some dates can't be reliably split, so they create a note" test="//bf:Instance[1]/bf:note[3]/bf:Note/bf:noteType[text()='Numbering']/parent::*/rdfs:label = '[Dai 1-gō] (Shōwa 41-nen 12-gatsu [Dec. 1966])'"/>
182+
<x:expect label="But we should be able to parse if there is a ')-' in the string" test="//bf:Instance[1]/bf:firstIssue[3] = 'Vol. 1 (1865-1866)'"/>
183+
<x:expect label="Trailing hyphen creates only firstIssue property" test="//bf:Instance[2]/bf:firstIssue = 'No. 1' and count(//bf:Instance[2]/bf:lastIssue) = 0"/>
184+
<x:expect label="Leading hyphen creates only lastIssue property" test="//bf:Instance[3]/bf:lastIssue = '6th (Sept. 28, 1972).' and count(//bf:Instance[3]/bf:firstIssue) = 0"/>
185+
</x:scenario>
175186

176187
<x:scenario label="380 - FORM OF WORK">
177188
<x:context href="data/ConvSpec-3XX/marc.xml"/>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
<!-- 362 edge cases -->
2+
<collection xmlns="http://www.loc.gov/MARC21/slim">
3+
<record>
4+
<controlfield tag="001">1</controlfield>
5+
<!-- unformatted dates -->
6+
<datafield tag="362" ind1="0" ind2=" ">
7+
<subfield code="a">Began in 1989</subfield>
8+
</datafield>
9+
<!-- legacy formatting -->
10+
<datafield tag="362" ind1="0" ind2=" ">
11+
<subfield code="a">no. 1-3; 1975-1977.</subfield>
12+
</datafield>
13+
<!-- parallel statements -->
14+
<datafield tag="362" ind1="0" ind2=" ">
15+
<subfield code="a">Vol. 62 (May 1959)-v. 73 (Jan. 1970) = No. 768-896.</subfield>
16+
</datafield>
17+
<!-- too many hyphens -->
18+
<datafield tag="362" ind1="0" ind2=" ">
19+
<subfield code="a">[Dai 1-gō] (Shōwa 41-nen 12-gatsu [Dec. 1966])</subfield>
20+
</datafield>
21+
<!-- ')-' parsing -->
22+
<datafield tag="362" ind1="0" ind2=" ">
23+
<subfield code="a">Vol. 1 (1865-1866)-v. 62 (1926-1927).</subfield>
24+
</datafield>
25+
</record>
26+
<record>
27+
<controlfield tag="001">2</controlfield>
28+
<!-- trailing hyphen -->
29+
<datafield tag="362" ind1="0" ind2=" ">
30+
<subfield code="a">No. 1-</subfield>
31+
</datafield>
32+
</record>
33+
<record>
34+
<controlfield tag="001">3</controlfield>
35+
<!-- leading hyphen -->
36+
<datafield tag="362" ind1="0" ind2=" ">
37+
<subfield code="a">-6th (Sept. 28, 1972).</subfield>
38+
</datafield>
39+
</record>
40+
</collection>

xsl/ConvSpec-3XX.xsl

Lines changed: 168 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1100,45 +1100,182 @@
11001100
<xsl:template match="marc:datafield[@tag='362' or @tag='880']" mode="instance362">
11011101
<xsl:param name="serialization" select="'rdfxml'"/>
11021102
<xsl:variable name="vXmlLang"><xsl:apply-templates select="." mode="xmllang"/></xsl:variable>
1103-
<xsl:variable name="vFirstIssue"><xsl:value-of select="substring-before(marc:subfield[@code='a'],'-')"/></xsl:variable>
1104-
<xsl:variable name="vLastIssue"><xsl:value-of select="substring-after(marc:subfield[@code='a'],'-')"/></xsl:variable>
11051103
<xsl:choose>
1106-
<xsl:when test="$serialization = 'rdfxml'">
1104+
<xsl:when test="@ind1='0'">
11071105
<xsl:choose>
1108-
<xsl:when test="@ind1='0'">
1109-
<xsl:if test="$vFirstIssue != ''">
1110-
<bf:firstIssue>
1111-
<xsl:if test="$vXmlLang != ''">
1112-
<xsl:attribute name="xml:lang"><xsl:value-of select="$vXmlLang"/></xsl:attribute>
1113-
</xsl:if>
1114-
<xsl:value-of select="$vFirstIssue"/>
1115-
</bf:firstIssue>
1116-
</xsl:if>
1117-
<xsl:if test="$vLastIssue != ''">
1118-
<bf:lastIssue>
1119-
<xsl:if test="$vXmlLang != ''">
1120-
<xsl:attribute name="xml:lang"><xsl:value-of select="$vXmlLang"/></xsl:attribute>
1121-
</xsl:if>
1122-
<xsl:value-of select="$vLastIssue"/>
1123-
</bf:lastIssue>
1124-
</xsl:if>
1106+
<!-- process as a note under some conditions -->
1107+
<xsl:when test="contains(marc:subfield[@code='a'],';')
1108+
or not(contains(marc:subfield[@code='a'],'-'))">
1109+
<xsl:call-template name="numberingNote">
1110+
<xsl:with-param name="serialization" select="$serialization"/>
1111+
<xsl:with-param name="pXmlLang" select="$vXmlLang"/>
1112+
<xsl:with-param name="pNote" select="marc:subfield[@code='a']/text()"/>
1113+
</xsl:call-template>
1114+
</xsl:when>
1115+
<!-- '=' indicates parallel statements -->
1116+
<xsl:when test="contains(marc:subfield[@code='a'],'=')">
1117+
<xsl:choose>
1118+
<xsl:when test="not(contains(substring-after(marc:subfield[@code='a'],'='),'='))">
1119+
<xsl:variable name="vStatement1">
1120+
<xsl:value-of select="normalize-space(substring-before(marc:subfield[@code='a'],'='))"/>
1121+
</xsl:variable>
1122+
<xsl:variable name="vStatement2">
1123+
<xsl:value-of select="normalize-space(substring-after(marc:subfield[@code='a'],'='))"/>
1124+
</xsl:variable>
1125+
<!-- first statement -->
1126+
<xsl:choose>
1127+
<xsl:when test="contains($vStatement1,'&#x00029;-')">
1128+
<xsl:call-template name="firstLastIssue">
1129+
<xsl:with-param name="serialization" select="$serialization"/>
1130+
<xsl:with-param name="pXmlLang" select="$vXmlLang"/>
1131+
<xsl:with-param name="pFirstIssue" select="concat(substring-before($vStatement1,'&#x00029;-'),'&#x00029;')"/>
1132+
<xsl:with-param name="pLastIssue" select="substring-after($vStatement1,'&#x00029;-')"/>
1133+
</xsl:call-template>
1134+
</xsl:when>
1135+
<xsl:when test="contains($vStatement1,'-')
1136+
and not(contains(substring-after($vStatement1,'-'),'-'))">
1137+
<xsl:call-template name="firstLastIssue">
1138+
<xsl:with-param name="serialization" select="$serialization"/>
1139+
<xsl:with-param name="pXmlLang" select="$vXmlLang"/>
1140+
<xsl:with-param name="pFirstIssue" select="substring-before($vStatement1,'-')"/>
1141+
<xsl:with-param name="pLastIssue" select="substring-after($vStatement1,'-')"/>
1142+
</xsl:call-template>
1143+
</xsl:when>
1144+
<xsl:otherwise>
1145+
<xsl:call-template name="numberingNote">
1146+
<xsl:with-param name="serialization" select="$serialization"/>
1147+
<xsl:with-param name="pXmlLang" select="$vXmlLang"/>
1148+
<xsl:with-param name="pNote" select="$vStatement1"/>
1149+
</xsl:call-template>
1150+
</xsl:otherwise>
1151+
</xsl:choose>
1152+
<!-- second statement -->
1153+
<xsl:choose>
1154+
<xsl:when test="contains($vStatement2,'&#x00029;-')">
1155+
<xsl:call-template name="firstLastIssue">
1156+
<xsl:with-param name="serialization" select="$serialization"/>
1157+
<xsl:with-param name="pXmlLang" select="$vXmlLang"/>
1158+
<xsl:with-param name="pFirstIssue" select="concat(substring-before($vStatement2,'&#x00029;-'),'&#x00029;')"/>
1159+
<xsl:with-param name="pLastIssue" select="substring-after($vStatement2,'&#x00029;-')"/>
1160+
</xsl:call-template>
1161+
</xsl:when>
1162+
<xsl:when test="contains($vStatement2,'-')
1163+
and not(contains(substring-after($vStatement2,'-'),'-'))">
1164+
<xsl:call-template name="firstLastIssue">
1165+
<xsl:with-param name="serialization" select="$serialization"/>
1166+
<xsl:with-param name="pXmlLang" select="$vXmlLang"/>
1167+
<xsl:with-param name="pFirstIssue" select="substring-before($vStatement2,'-')"/>
1168+
<xsl:with-param name="pLastIssue" select="substring-after($vStatement2,'-')"/>
1169+
</xsl:call-template>
1170+
</xsl:when>
1171+
<xsl:otherwise>
1172+
<xsl:call-template name="numberingNote">
1173+
<xsl:with-param name="serialization" select="$serialization"/>
1174+
<xsl:with-param name="pXmlLang" select="$vXmlLang"/>
1175+
<xsl:with-param name="pNote" select="$vStatement2"/>
1176+
</xsl:call-template>
1177+
</xsl:otherwise>
1178+
</xsl:choose>
1179+
</xsl:when>
1180+
<xsl:otherwise>
1181+
<xsl:call-template name="numberingNote">
1182+
<xsl:with-param name="serialization" select="$serialization"/>
1183+
<xsl:with-param name="pXmlLang" select="$vXmlLang"/>
1184+
<xsl:with-param name="pNote" select="marc:subfield[@code='a']/text()"/>
1185+
</xsl:call-template>
1186+
</xsl:otherwise>
1187+
</xsl:choose>
11251188
</xsl:when>
1189+
<!-- ')-' as split between first/last -->
1190+
<xsl:when test="contains(marc:subfield[@code='a'],'&#x00029;-')">
1191+
<xsl:call-template name="firstLastIssue">
1192+
<xsl:with-param name="serialization" select="$serialization"/>
1193+
<xsl:with-param name="pXmlLang" select="$vXmlLang"/>
1194+
<xsl:with-param name="pFirstIssue" select="concat(substring-before(marc:subfield[@code='a'],'&#x00029;-'),'&#x00029;')"/>
1195+
<xsl:with-param name="pLastIssue" select="substring-after(marc:subfield[@code='a'],'&#x00029;-')"/>
1196+
</xsl:call-template>
1197+
</xsl:when>
1198+
<!-- more than one hyphen, too hard to parse -->
1199+
<xsl:when test="contains(substring-after(marc:subfield[@code='a'],'-'),'-')">
1200+
<xsl:call-template name="numberingNote">
1201+
<xsl:with-param name="serialization" select="$serialization"/>
1202+
<xsl:with-param name="pXmlLang" select="$vXmlLang"/>
1203+
<xsl:with-param name="pNote" select="marc:subfield[@code='a']/text()"/>
1204+
</xsl:call-template>
1205+
</xsl:when>
1206+
<!-- the standard case (one hyphen, not parallel) -->
11261207
<xsl:otherwise>
1127-
<bf:note>
1128-
<bf:Note>
1129-
<bf:noteType>Numbering</bf:noteType>
1130-
<rdfs:label>
1131-
<xsl:if test="$vXmlLang != ''">
1132-
<xsl:attribute name="xml:lang"><xsl:value-of select="$vXmlLang"/></xsl:attribute>
1133-
</xsl:if>
1134-
<xsl:value-of select="marc:subfield[@code='a']"/>
1135-
</rdfs:label>
1136-
</bf:Note>
1137-
</bf:note>
1208+
<xsl:call-template name="firstLastIssue">
1209+
<xsl:with-param name="serialization" select="$serialization"/>
1210+
<xsl:with-param name="pXmlLang" select="$vXmlLang"/>
1211+
<xsl:with-param name="pFirstIssue" select="substring-before(marc:subfield[@code='a'],'-')"/>
1212+
<xsl:with-param name="pLastIssue" select="substring-after(marc:subfield[@code='a'],'-')"/>
1213+
</xsl:call-template>
11381214
</xsl:otherwise>
11391215
</xsl:choose>
11401216
</xsl:when>
1217+
<xsl:otherwise>
1218+
<xsl:call-template name="numberingNote">
1219+
<xsl:with-param name="serialization" select="$serialization"/>
1220+
<xsl:with-param name="pXmlLang" select="$vXmlLang"/>
1221+
<xsl:with-param name="pNote" select="marc:subfield[@code='a']/text()"/>
1222+
</xsl:call-template>
1223+
</xsl:otherwise>
1224+
</xsl:choose>
1225+
</xsl:template>
1226+
1227+
<xsl:template name="numberingNote">
1228+
<xsl:param name="serialization" select="'rdfxml'"/>
1229+
<xsl:param name="pXmlLang"/>
1230+
<xsl:param name="pNote"/>
1231+
<xsl:choose>
1232+
<xsl:when test="$serialization='rdfxml'">
1233+
<bf:note>
1234+
<bf:Note>
1235+
<bf:noteType>Numbering</bf:noteType>
1236+
<rdfs:label>
1237+
<xsl:if test="$pXmlLang != ''">
1238+
<xsl:attribute name="xml:lang"><xsl:value-of select="$pXmlLang"/></xsl:attribute>
1239+
</xsl:if>
1240+
<xsl:value-of select="$pNote"/>
1241+
</rdfs:label>
1242+
</bf:Note>
1243+
</bf:note>
1244+
</xsl:when>
11411245
</xsl:choose>
11421246
</xsl:template>
11431247

1248+
<xsl:template name="firstLastIssue">
1249+
<xsl:param name="serialization" select="'rdfxml'"/>
1250+
<xsl:param name="pXmlLang"/>
1251+
<xsl:param name="pFirstIssue"/>
1252+
<xsl:param name="pLastIssue"/>
1253+
<xsl:message>first issue: <xsl:value-of select="$pFirstIssue"/></xsl:message>
1254+
<xsl:message>last issue: <xsl:value-of select="$pLastIssue"/></xsl:message>
1255+
<xsl:if test="$pFirstIssue != ''">
1256+
<xsl:choose>
1257+
<xsl:when test="$serialization='rdfxml'">
1258+
<bf:firstIssue>
1259+
<xsl:if test="$pXmlLang != ''">
1260+
<xsl:attribute name="xml:lang"><xsl:value-of select="$pXmlLang"/></xsl:attribute>
1261+
</xsl:if>
1262+
<xsl:value-of select="$pFirstIssue"/>
1263+
</bf:firstIssue>
1264+
</xsl:when>
1265+
</xsl:choose>
1266+
</xsl:if>
1267+
<xsl:if test="$pLastIssue != ''">
1268+
<xsl:choose>
1269+
<xsl:when test="$serialization='rdfxml'">
1270+
<bf:lastIssue>
1271+
<xsl:if test="$pXmlLang != ''">
1272+
<xsl:attribute name="xml:lang"><xsl:value-of select="$pXmlLang"/></xsl:attribute>
1273+
</xsl:if>
1274+
<xsl:value-of select="$pLastIssue"/>
1275+
</bf:lastIssue>
1276+
</xsl:when>
1277+
</xsl:choose>
1278+
</xsl:if>
1279+
</xsl:template>
1280+
11441281
</xsl:stylesheet>

0 commit comments

Comments
 (0)