Skip to content

Instantly share code, notes, and snippets.

@kefo
Last active August 29, 2015 14:02
Show Gist options
  • Save kefo/63bcb45fa2da1b8d7215 to your computer and use it in GitHub Desktop.
Save kefo/63bcb45fa2da1b8d7215 to your computer and use it in GitHub Desktop.
MARC/TXT to MARC/XML
declare namespace marcxml = "http://www.loc.gov/MARC21/slim";
let $mtexts := ('000 02018nas a2200433Ia 450
001 8277786
005 20140505165744.0
008 140505c198u9999cc uu p 0 e0chi d
035 __ |a (OCoLC)ocn879220545
040 __ |a CSt-H |b eng |c PULEA |d OCLCQ |d PULEA
035 __ |a (OCoLC)879220545
043 __ |a a-cc---
079 __ |a ocn145400445
090 __ |a PL2446 |b .T88
049 __ |a MAIN
130 0_ |6 880-01 |a Tong su wen xue xuan kan (Beijing, China)
245 10 |6 880-02 |a Tong su wen xue xuan kan.
260 __ |6 880-03 |a Beijing : |b "Tong su wen xue xuan kan" bian ji bu, |c 1988-
300 __ |a v. : |b ill. ; |c 28 cm.
362 1_ |6 880-04 |a Began with: chuang kan hao = zong di 1 qi, published in 1988.
550 __ |6 880-05 |a Sponsored by: :Zhongguo min jian wen yi jia xie hui, and: Zhongguo da zhong wen xue xue hui.
588 __ |6 880-06 |a Description based on: Chuang kan hao = zong di 1 qi;title from cover.
588 __ |6 880-07 |a Latest issue consulted: zong di 3 qi.
650 0 |a Chinese literature |y 20th century |v Periodicals.
651 _0 |a China |x Politics and government |v Periodicals.
710 2 |6 880-08 |a Zhongguo min jian wen yi jia xie hui, |e sponsoring body.
710 2_ |6 880-09 |a Zhongguo da zhong wen xue xue hui, |e sponsoring body.
776 08 |i Online version: |t Tong su wen xue xuan kan |w (OCoLC)744498757
880 0_ |6 130-01 |a 通俗文学选刊 (Beijing, China)
880 10 |6 245-02 |a 通俗文学选刊.
880 __ |6 260-03 |a 北京 : |b 《通俗文学选刊》编辑部, |c 1988-
880 1_ |6 362-04 |a Began with: 创刊号 = 总第1期, published in 1988.
880 __ |6 550-05 |a Sponsored by: 中国民间文艺家协会, and: 中国大众文学学会.
880 __ |6 588-06 |a Description based on: 创刊号 = 总第1期; title from cover.
880 __ |6 588-07 |a Latest issue consulted: 总第3期.
880 2_ |6 710-08 |a 中国民间文艺家协会, |e sponsoring body.
880 2_ |6 710-09 |a 中国大众文学学会, |e sponsoring body. ',
'000 01532cam a22004454a 450
001 7574800
005 20140307173446.0
008 130202s2013 ua b 000 0 ara c
010 __ |a 2013339535
035 __ |a (OCoLC)ocn871722854
035 __ |a (EG-CaLB)54601
040 __ |a LEILA |b eng |c PUL
066 __ |c (3
020 __ |a 9789776234079
020 __ |a 9776234070
035 __ |a (OCoLC)871722854
035 __ |a (DLC)2013339535
042 __ |a pcc |a lcode
043 __ |a f-ua--- |a f-ti---
050 00 |a DT70 |b .M375 2013
079 __ |a ocn826639218
049 __ |a PULL
100 1_ |6 880-01 |a Mashbāl, Muḥammad, |e author.
245 10 |6 880-02 |a Miṣr fī ʻuyūn al-Maghāribah / |c Muḥammad Mashbāl.
250 __ |6 880-03 |a al-Ṭabʻah 1.
260 __ |6 880-04 |a al-Qāhirah : |b al-Markaz al-ʻArabī lil-Dirāsāt al-Gharbīyah, |c 2013.
300 __ |a 224 p. ; |c 20 cm.
504 __ |a Includes bibliographical references.
651 0 |a Egypt |x Intellectual life |y 20th century.
651 _0 |a Egypt |x In literature.
651 _0 |a Egypt |x Relations |z Tunisia.
651 _0 |a Tunisia |x Relations |z Egypt.
880 1 |6 100-01/(3/r |a مشبال، محمد، |e author.
880 10 |6 245-02/(3/r |a مصر في عيون المغاربة / |c محمد مشبال.
880 __ |6 250-03/(3/r |a الطبعة 1.
880 __ |6 260-04/(3/r |a القاهرة : |b المركز العربي للدراسات الغربية، |c 2013.
')
let $records :=
for $mtext in $mtexts
let $lines := fn:tokenize($mtext, "\n")
let $fields :=
for $l in $lines
let $field := fn:substring($l, 1, 3)
let $ind1 := fn:substring($l, 5, 1)
let $ind1 :=
if (xs:int($field) > 9) then
if ( $ind1 eq "_") then
" "
else
$ind1
else
"n/a"
let $ind2 := fn:substring($l, 6, 1)
let $ind2 :=
if (xs:int($field) > 9) then
if ( $ind2 eq "_") then
" "
else
$ind2
else
"n/a"
let $sfieldstr := fn:substring-after($l, "|")
let $sfields :=
if (xs:int($field) > 9) then
if (fn:contains($sfieldstr, "|")) then
for $sfstr in fn:tokenize($sfieldstr, "\|")
let $sfield := fn:substring(fn:normalize-space($sfstr), 1, 1)
let $sfdata := fn:substring($sfstr, 3)
return
element marcxml:subfield {
attribute code {$sfield},
xs:string($sfdata)
}
else
let $sfield := fn:substring(fn:normalize-space($sfieldstr), 1, 1)
let $sfdata := fn:substring($sfieldstr, 3)
return
element marcxml:subfield {
attribute code {$sfield},
xs:string($sfdata)
}
else
()
return
if (xs:int($field) eq 0) then
element marcxml:leader { fn:normalize-space(fn:substring($l, 4)) }
else if (xs:int($field) < 10) then
element marcxml:controlfield {
attribute tag {$field},
fn:normalize-space(fn:substring($l, 4))
}
else
element marcxml:datafield {
attribute tag {$field},
attribute ind1 {$ind1},
attribute ind2 {$ind2},
$sfields
}
return
element marcxml:record {
$fields
}
return
element marcxml:collection {
$records
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment