Project

General

Profile

Revision 4552

Added by walbridge about 12 years ago

Transform EML 2.0.x documents to 2.1.0 which are found when editing with the registry, using an XSLT transformation.

View differences:

register-dataset.cgi
1851 1851

  
1852 1852
################################################################################
1853 1853
# 
1854
# Convert EML 2.0.x documents into 2.1.0 using an XSLT transform
1855
#
1856
################################################################################
1857
sub transformEmlTo210 {
1858
    my $xmldoc = shift;
1859
    my $xslt = XML::LibXSLT->new();
1860
    my $results;
1861
    my $stylesheet;
1862
    my $resultsheet;
1863

  
1864
    my $transform = "$styleCommonPath/conversions/eml201to210.xsl";
1865
    $stylesheet = $xslt->parse_stylesheet_file($transform);
1866
    $results = $stylesheet->transform($doc);
1867
    #my $out = "$emldir/test-210.xml";
1868
    #open (TFILE,">$out") || die("Can't open xml file...\n");
1869
    #print TFILE $stylesheet->output_string($results);
1870
    #close(TFILE);
1871
    #print "Output $out.\n";
1872
    return $results;
1873
}
1874

  
1875
################################################################################
1876
# 
1854 1877
# Parse an EML 2.x file and extract the metadata into perl variables for 
1855 1878
# processing and returning to the template processor
1856 1879
#
......
1872 1895
    $$templateVars{'show'} = $show;
1873 1896
    $$templateVars{'site'} = $config->{'site'};
1874 1897

  
1898
    # get the document namespace
1899
    my $root = $doc->getDocumentElement();
1900
    my $emlns = $root->lookupNamespaceURI("eml");
1901
    if ($emlns =~ 'eml-2.0') {
1902
        $doc = transformEmlTo210($doc);
1903
    }
1904
    elsif ($emlns =~ 'eml-2.1') {
1905
        debug("Registry: Translation: Found a 2.1.x doc.");
1906
    }
1907
    else {
1908
        $error = "Unrecognized document type!";
1909
        debug("Registry: Translation: $error"); 
1910
        push(@errorMessages, $error."\n");
1911
    }
1912

  
1875 1913
    # find out the tag <alternateIdentifier>. 
1876 1914
    $results = $doc->findnodes('//dataset/alternateIdentifier');
1877 1915
    if ($results->size() > 1) {
......
2538 2576
    push (@fileArray, $docid);
2539 2577
    $parser = XML::LibXML->new();
2540 2578

  
2541
        $httpMessage = $metacat->read($docid);
2579
    $httpMessage = $metacat->read($docid);
2542 2580
    $doc = $httpMessage->content();    
2543 2581
    $doc = delNormalize($doc);
2544 2582
    $xmldoc = $parser->parse_string($doc);

Also available in: Unified diff