Skip to content
Snippets Groups Projects
Commit 76f2ea8a authored by Andreas Romeyke's avatar Andreas Romeyke
Browse files

- improved debugging

- fixed xslt for response to marc transformation
parent 5b710fe2
No related branches found
No related tags found
No related merge requests found
...@@ -52,7 +52,7 @@ sub patch_mods($) { ...@@ -52,7 +52,7 @@ sub patch_mods($) {
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mods="http://www.loc.gov/mods/v3" xmlns:mods="http://www.loc.gov/mods/v3"
xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-5.xsd" xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-6.xsd"
exclude-result-prefixes="xs" exclude-result-prefixes="xs"
version="1.0"> version="1.0">
<xsl:output encoding="UTF-8" indent="yes" method="xml"/> <xsl:output encoding="UTF-8" indent="yes" method="xml"/>
...@@ -79,12 +79,13 @@ sub patch_marc_response($) { ...@@ -79,12 +79,13 @@ sub patch_marc_response($) {
my $xslt_patch_string =<<PATCH2; my $xslt_patch_string =<<PATCH2;
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.loc.gov/MARC21/slim" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="http://www.loc.gov/MARC21/slim" xmlns:srw="http://www.loc.gov/zing/srw/"
exclude-result-prefixes="" version="1.0"> exclude-result-prefixes="srw" version="1.0">
<xsl:template match="/record"> <xsl:template match="/record">
<xsl:element name="collection"> <xsl:element name="collection">
<xsl:element name="{local-name()}" namespace="http://www.loc.gov/MARC21/slim"> <xsl:element name="record" namespace="http://www.loc.gov/MARC21/slim">
<xsl:apply-templates select="node() | @*"/> <xsl:apply-templates select="@*"/>
<xsl:apply-templates select="node()"/>
</xsl:element> </xsl:element>
</xsl:element> </xsl:element>
</xsl:template> </xsl:template>
...@@ -93,6 +94,11 @@ sub patch_marc_response($) { ...@@ -93,6 +94,11 @@ sub patch_marc_response($) {
<xsl:apply-templates select="node() | @*"/> <xsl:apply-templates select="node() | @*"/>
</xsl:element> </xsl:element>
</xsl:template> </xsl:template>
<xsl:template match="@*">
<xsl:attribute name="{local-name()}">
<xsl:value-of select="."/>
</xsl:attribute>
</xsl:template>
</xsl:stylesheet> </xsl:stylesheet>
PATCH2 PATCH2
my $xslt = XML::LibXSLT->new(); my $xslt = XML::LibXSLT->new();
...@@ -107,6 +113,8 @@ PATCH2 ...@@ -107,6 +113,8 @@ PATCH2
# the "old" approach does not handle umlauts or UTF8-chars above ASCII table # the "old" approach does not handle umlauts or UTF8-chars above ASCII table
# old: http://swb2.bsz-bw.de/sru/DB=2.1/username=/password=/?query=pica.ppn+%3D+"494384174"&startRecord=1&maximumRecords=10&recordSchema=marcxml # old: http://swb2.bsz-bw.de/sru/DB=2.1/username=/password=/?query=pica.ppn+%3D+"494384174"&startRecord=1&maximumRecords=10&recordSchema=marcxml
# new: http://swb2.bsz-bw.de/sru/DB=2.1/username=/password=/?query=pica.ppn+%3D+"494384174"&startRecord=1&maximumRecords=10&recordSchema=marc21&recordPacking=xml&version=1.1 # new: http://swb2.bsz-bw.de/sru/DB=2.1/username=/password=/?query=pica.ppn+%3D+"494384174"&startRecord=1&maximumRecords=10&recordSchema=marc21&recordPacking=xml&version=1.1
# with stylesheet:
# http://swb2.bsz-bw.de/sru/DB=2.1/username=/password=/?query=pica.ppn+%3D+%22494384174%22&version=1.1&operation=searchRetrieve&stylesheet=http%3A%2F%2Fswb2.bsz-bw.de%2Fsru%2FDB%3D2.1%2F%3Fxsl%3DsearchRetrieveResponse&recordSchema=marc21&maximumRecords=10&startRecord=1&recordPacking=xml&sortKeys=none&x-info-5-mg-requestGroupings=none
sub get_mods_from ($$) { # $mods = ($url, $ppn) sub get_mods_from ($$) { # $mods = ($url, $ppn)
my $url = shift; my $url = shift;
my $ppn = shift; # example: "457035137" for "Der Fichtelberg" my $ppn = shift; # example: "457035137" for "Der Fichtelberg"
...@@ -124,7 +132,7 @@ sub get_mods_from ($$) { # $mods = ($url, $ppn) ...@@ -124,7 +132,7 @@ sub get_mods_from ($$) { # $mods = ($url, $ppn)
#my $sruschema="marcxml"; #my $sruschema="marcxml";
my $sruschema="marc21"; my $sruschema="marc21";
#my $sru = "${srubase}?query=${srusearchkey}+%3D+%22${sruvalue}%22&startRecord=1&maximumRecords=${srumaxrecords}&recordSchema=${sruschema}"; #my $sru = "${srubase}?query=${srusearchkey}+%3D+%22${sruvalue}%22&startRecord=1&maximumRecords=${srumaxrecords}&recordSchema=${sruschema}";
my $sru = "${srubase}?query=${srusearchkey}+%3D+%22${sruvalue}%22&startRecord=1&maximumRecords=${srumaxrecords}&recordSchema=${sruschema}&recordPacking=xml&version=1.1"; my $sru = "${srubase}?query=${srusearchkey}+%3D+%22${sruvalue}%22&startRecord=1&maximumRecords=${srumaxrecords}&recordSchema=${sruschema}&recordPacking=xml&version=1.1&stylesheet=http%3A%2F%2Fswb2.bsz-bw.de%2Fsru%2FDB%3D2.1%2F%3Fxsl%3DsearchRetrieveResponse";
#p ($sru); # debug output #p ($sru); # debug output
my $record = $ua->get($sru); # ask SWB for given PPN my $record = $ua->get($sru); # ask SWB for given PPN
if ($record->is_success) { if ($record->is_success) {
...@@ -132,6 +140,7 @@ sub get_mods_from ($$) { # $mods = ($url, $ppn) ...@@ -132,6 +140,7 @@ sub get_mods_from ($$) { # $mods = ($url, $ppn)
my $xp = XML::XPath->new( $record->decoded_content ); my $xp = XML::XPath->new( $record->decoded_content );
my $parser = XML::LibXML->new(); my $parser = XML::LibXML->new();
if ($with_debug) { if ($with_debug) {
say "write DEBUG_${ppn}_response.xml";
write_file("DEBUG_${ppn}_response.xml", {binmode => ':utf8'}, $record->decoded_content); write_file("DEBUG_${ppn}_response.xml", {binmode => ':utf8'}, $record->decoded_content);
} }
my $marcblob = $parser->parse_string( my $marcblob = $parser->parse_string(
...@@ -139,7 +148,9 @@ sub get_mods_from ($$) { # $mods = ($url, $ppn) ...@@ -139,7 +148,9 @@ sub get_mods_from ($$) { # $mods = ($url, $ppn)
); );
my $marcblob_patched = patch_marc_response( $marcblob ); my $marcblob_patched = patch_marc_response( $marcblob );
if ($with_debug) { if ($with_debug) {
say "write DEBUG_${ppn}_marc_unpatched.xml";
write_file("DEBUG_${ppn}_marc_unpatched.xml", {binmode => ':utf8'}, $marcblob); write_file("DEBUG_${ppn}_marc_unpatched.xml", {binmode => ':utf8'}, $marcblob);
say "write DEBUG_${ppn}_marc.xml";
write_file("DEBUG_${ppn}_marc.xml", {binmode => ':utf8'}, $marcblob_patched); write_file("DEBUG_${ppn}_marc.xml", {binmode => ':utf8'}, $marcblob_patched);
} }
my $xslt = XML::LibXSLT->new(); my $xslt = XML::LibXSLT->new();
...@@ -148,6 +159,7 @@ sub get_mods_from ($$) { # $mods = ($url, $ppn) ...@@ -148,6 +159,7 @@ sub get_mods_from ($$) { # $mods = ($url, $ppn)
my $marc = $parser->parse_string( $marcblob_patched ); my $marc = $parser->parse_string( $marcblob_patched );
my $result = $stylesheet->transform( $marc); my $result = $stylesheet->transform( $marc);
if ($with_debug) { if ($with_debug) {
say "write DEBUG_${ppn}_unpatched_mods.xml";
write_file("DEBUG_${ppn}_unpatched_mods.xml", {binmode => ':utf8'}, $stylesheet->output_string( $result )); write_file("DEBUG_${ppn}_unpatched_mods.xml", {binmode => ':utf8'}, $stylesheet->output_string( $result ));
} }
$result = patch_mods( $result); $result = patch_mods( $result);
...@@ -247,7 +259,7 @@ my $mods; ...@@ -247,7 +259,7 @@ my $mods;
if (defined $ppn) { if (defined $ppn) {
$mods = get_mods_from($url, $ppn); $mods = get_mods_from($url, $ppn);
if (1 == $with_debug) { if (1 == $with_debug) {
write_file("DEBUG_${ppn}_mods.xml", $mods); write_file("DEBUG_${ppn}_mods.xml", {binmode => ':utf8'}, $mods);
} }
# remove the <xml /> from beginning of the answer # remove the <xml /> from beginning of the answer
$mods=~ s#<\?xml version="1.0" encoding="UTF-8"\?>#<!-- removed xml header from mods part -->#; $mods=~ s#<\?xml version="1.0" encoding="UTF-8"\?>#<!-- removed xml header from mods part -->#;
...@@ -349,7 +361,7 @@ METS ...@@ -349,7 +361,7 @@ METS
# compress if needed # compress if needed
if (!defined $as_zip) { if (!defined $as_zip) {
write_file( "${output}/${sip_root_dir}/sip.xml", $sip ); write_file( "${output}/${sip_root_dir}/sip.xml",{binmode => ':utf8'}, $sip );
# copy source to target # copy source to target
foreach my $source (sort keys (%filecopyhash)) { foreach my $source (sort keys (%filecopyhash)) {
my $target = $filecopyhash{$source}->{"target"}; my $target = $filecopyhash{$source}->{"target"};
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment