diff --git a/perl/exit_strategy.pl b/perl/exit_strategy.pl index 05aaeff18e78ce7b3bc2aea85c78c1e178dc3912..c901ae8b149bac0aec5070bd36d92e325829d7b9 100644 --- a/perl/exit_strategy.pl +++ b/perl/exit_strategy.pl @@ -270,16 +270,11 @@ sub check_if_db_conform ($$) { { my $compiled_xpath_titles = XML::LibXML::XPathExpression->new('/mets:mets/mets:dmdSec/mets:mdWrap[1]/mets:xmlData[1]/dc:record/dc:title[1]'); my $compiled_xpath_dcrecords = XML::LibXML::XPathExpression->new('/mets:mets/mets:dmdSec/mets:mdWrap/mets:xmlData/dc:record/*'); - my $compiled_xpath_amdsecs = XML::LibXML::XPathExpression->new('/mets:mets/mets:amdSec[starts-with(@ID, \'REP\')]'); - my $str_local_reps = 'mets:techMD/mets:mdWrap/mets:xmlData/*[local-name()=\'dnx\']/*[local-name()=\'section\']/*[local-name()=\'record\']/*[local-name()=\'key\' and @id=\'label\']'; - my $compiled_xpath_localreps = XML::LibXML::XPathExpression->new( $str_local_reps); - my $compiled_xpath_localreps2 = XML::LibXML::XPathExpression->new('/mets:mets/mets:amdSec/mets:techMD/mets:mdWrap/mets:xmlData/dnx/section/record/key[@id=\'label\']=\'LOCAL\''); - my $compiled_xpath_filesec = XML::LibXML::XPathExpression->new('/mets:mets/mets:fileSec'); - my $compiled_xpath_flocat = XML::LibXML::XPathExpression->new('mets:file/mets:FLocat'); - my $compiled_xpath_id = XML::LibXML::XPathExpression->new('@ID'); - my $compiled_xpath_admid = XML::LibXML::XPathExpression->new('@ADMID'); - my $compiled_xpath_xlinhref = XML::LibXML::XPathExpression->new('@xlin:href'); - my $compiled_xpath_dot = XML::LibXML::XPathExpression->new('.'); + my $compiled_xpath_repid = XML::LibXML::XPathExpression->new('/mets:mets/mets:amdSec[starts-with(@ID, \'REP\')]/@ID'); + my $str_local_record = "mets:techMD/mets:mdWrap/mets:xmlData/*[local-name()=\'dnx\']/*[local-name()=\'section\']/*[local-name()=\'record\']"; + my $str_local_reps = "$str_local_record/*[local-name()=\'key\' and \@id=\'label\' and (. = \'LOCAL\' or . = \'LZA_INTERN\' or . = \'LZA\')]"; + my $str_repid_old = "/mets:mets/mets:amdSec[starts-with(\@ID, \'REP\') and $str_local_reps]/\@ID"; + my $compiled_xpath_repid_old = XML::LibXML::XPathExpression->new($str_repid_old); ############################################################ sub get_title { my $xp = shift; @@ -317,27 +312,13 @@ sub check_if_db_conform ($$) { my $xp = shift; my $filename = shift; my $repid; - my $repids = $xp->find($compiled_xpath_amdsecs); #/mets:mets/mets:amdSec - my @repnodes = $repids->get_nodelist; + my @repnodes = $xp->findnodes($compiled_xpath_repid); #/mets:mets/mets:amdSec/@ID my $found = scalar @repnodes; if (1 == $found) { - $repid = $repnodes[0]->findvalue($compiled_xpath_id); + $repid = $repnodes[0]->nodeValue; } elsif ($found > 1) { #multiple representations found # choose reppid with LZA, LZA_INTERN or LOCAL (for very old IEs) - foreach my $node (@repnodes) { - my $id = $node->findvalue($compiled_xpath_id); - check_if_db_conform($id, $filename); - my $localreps = $node->findvalue($compiled_xpath_localreps); - if ( - ($localreps eq 'LOCAL') - or ($localreps eq 'LZA') - or ($localreps eq 'LZA_INTERN') - ) { - $repid = $id; - last; - } - #print XML::XPath::XMLParser::as_string($node), "\n\n"; - } + $repid = $xp->findvalue( $compiled_xpath_repid_old); } # if $found == 0 do nothing return $repid;