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

- improved get_repid() using specialized xpath expressions

parent 11c99a06
No related branches found
No related tags found
No related merge requests found
......@@ -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;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment