r4552 - trunk/src/perl

walbridge at ecoinformatics.org walbridge at ecoinformatics.org
Mon Nov 10 18:07:57 PST 2008


Author: walbridge
Date: 2008-11-10 18:07:57 -0800 (Mon, 10 Nov 2008)
New Revision: 4552

Modified:
   trunk/src/perl/register-dataset.cgi
Log:
Transform EML 2.0.x documents to 2.1.0 which are found when editing with the registry, using an XSLT transformation.


Modified: trunk/src/perl/register-dataset.cgi
===================================================================
--- trunk/src/perl/register-dataset.cgi	2008-11-11 02:06:15 UTC (rev 4551)
+++ trunk/src/perl/register-dataset.cgi	2008-11-11 02:07:57 UTC (rev 4552)
@@ -1851,6 +1851,29 @@
 
 ################################################################################
 # 
+# Convert EML 2.0.x documents into 2.1.0 using an XSLT transform
+#
+################################################################################
+sub transformEmlTo210 {
+    my $xmldoc = shift;
+    my $xslt = XML::LibXSLT->new();
+    my $results;
+    my $stylesheet;
+    my $resultsheet;
+
+    my $transform = "$styleCommonPath/conversions/eml201to210.xsl";
+    $stylesheet = $xslt->parse_stylesheet_file($transform);
+    $results = $stylesheet->transform($doc);
+    #my $out = "$emldir/test-210.xml";
+    #open (TFILE,">$out") || die("Can't open xml file...\n");
+    #print TFILE $stylesheet->output_string($results);
+    #close(TFILE);
+    #print "Output $out.\n";
+    return $results;
+}
+
+################################################################################
+# 
 # Parse an EML 2.x file and extract the metadata into perl variables for 
 # processing and returning to the template processor
 #
@@ -1872,6 +1895,21 @@
     $$templateVars{'show'} = $show;
     $$templateVars{'site'} = $config->{'site'};
 
+    # get the document namespace
+    my $root = $doc->getDocumentElement();
+    my $emlns = $root->lookupNamespaceURI("eml");
+    if ($emlns =~ 'eml-2.0') {
+        $doc = transformEmlTo210($doc);
+    }
+    elsif ($emlns =~ 'eml-2.1') {
+        debug("Registry: Translation: Found a 2.1.x doc.");
+    }
+    else {
+        $error = "Unrecognized document type!";
+        debug("Registry: Translation: $error"); 
+        push(@errorMessages, $error."\n");
+    }
+
     # find out the tag <alternateIdentifier>. 
     $results = $doc->findnodes('//dataset/alternateIdentifier');
     if ($results->size() > 1) {
@@ -2538,7 +2576,7 @@
     push (@fileArray, $docid);
     $parser = XML::LibXML->new();
 
-        $httpMessage = $metacat->read($docid);
+    $httpMessage = $metacat->read($docid);
     $doc = $httpMessage->content();    
     $doc = delNormalize($doc);
     $xmldoc = $parser->parse_string($doc);



More information about the Metacat-cvs mailing list