File:  [LON-CAPA] / nsdl / prototypes / metadata_convert.pl
Revision 1.5: download - view: text, annotated - select for diffs
Sun May 12 16:48:18 2002 UTC (21 years, 11 months ago) by harris41
Branches: MAIN
CVS tags: HEAD
information on existing crosswalks as well as Dublin Core educational extensions
and endorsed IEEE LOM fields

    1: use XML::Xalan;
    2: 
    3: my $tr = new XML::Xalan::Transformer;
    4: 
    5: my $LONCAPA_metadata=(<<END);
    6: <abstract></abstract>
    7: <author>Felicia Berryman, MSU HHMI First Year Online Biology</author>
    8: <copyright>default</copyright>
    9: <creationdate>1011110523</creationdate>
   10: <dependencies></dependencies>
   11: <keywords>biomolecules,practice</keywords>
   12: <language>seniso</language>
   13: <lastrevisiondate>1011110523</lastrevisiondate>
   14: <mime>html</mime>
   15: <notes></notes>
   16: <owner>bio\@msu, bio\@msu (Michigan State University), bio\@msu (Michigan State University), bio\@msu (Michigan State University)</owner>
   17: <subject>Bio Information, Large Biomolecules - Intro, Large Biomolecules - Review</subject>
   18: <title>Test title</title>
   19: END
   20: 
   21: # ---------------------------------------------------- The 16 major nsdl fields
   22: # Audience
   23: # Publisher
   24: # Contributor
   25: # Relation
   26: # Coverage
   27: # Resource Identifier
   28: # Creator 
   29: # Resource Type
   30: # Date
   31: # Rights
   32: # Description
   33: # Source
   34: # Format
   35: # Subject & Keywords
   36: # Language
   37: # Title
   38: 
   39: 
   40: # --------------- also need educational recommended fields
   41: # http://dublincore.org/documents/2000/10/05/education-namespace/
   42: # dc-ed:audience
   43: # dc-ed:standard Element 
   44: # dc-ed:conformsTo (Qualifier to the dc:relation)
   45: # endorsement of the use of the InteractivityType,
   46: # InteractivityLevel, and TypicalLearningTime data elements (Education Category: 5.1, 5.3, and 5.9 respectively) from the IEEE Learning
   47: # Object Metadata (LOM) standard for P1484.12.
   48: 
   49: 
   50: # (there are also other identified cross-walk strategies for 8 other metadata
   51: #  standards)
   52: # crosswalks - http://128.253.121.110/NSDLmetaWG/IntroPage.html
   53: 
   54: 
   55: #http://metamanagement.comm.nsdlib.org/overview.html#NSDL
   56: #http://www.dlib.vt.edu/projects/OAi/marcxml/marcxml.html
   57: #http://www.openarchives.org/OAI/openarchivesprotocol.html
   58: # ">
   59: my $namespace='http://ExternalFunction/';
   60: my $func = sub {
   61:     my $text = shift;
   62:     return uc($text);
   63: };
   64: 
   65: $tr->install_function($namespace, 'plain-text', $func);
   66: 
   67: 
   68: my $NSDL_metadata1=(<<END);
   69: <?xml version="1.0"?>
   70: <dc xmlns="http://purl.org/dc/elements/1.1/"
   71:      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   72:      xsi:schemaLocation="http://purl.org/dc/elements/1.1
   73:      http://www.openarchives.org/OAI/1.1/dc.xsd">
   74: <title>The Cornell Law Quarterly</title>
   75: <date>1915-1916</date>
   76: <identifier>http://heinonline.org/HeinOnline/show.pl?
   77:             handle=hein.journals/clqv1%26id=1%26size=4</identifier>
   78: <rights>Available by Subscription. See http://www.wshein.com</rights>
   79: </dc>
   80: END
   81: open(OUT,'>tmpdc.xml');
   82: print(OUT <<END);
   83: $NSDL_metadata1
   84: END
   85: close(OUT);
   86: 
   87: my $NSDL_metadata2=(<<END);
   88: <dc:dc xmlns:dc="http://purl.org/dc/elements/1.1/" 
   89:        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
   90:        xsi:schemaLocation="http://purl.org/dc/elements/1.1/
   91:                            http://www.openarchives.org/OAI/1.1/dc.xsd">
   92: <dc:title>Grassmann's space analysis</dc:title> 
   93: <dc:creator>Hyde, E. W. (Edward Wyllys)</dc:creator>
   94: <dc:subject>LCSH:Ausdehnungslehre; LCCN QA205.H99</dc:subject>
   95: <dc:publisher>J. Wiley &amp; Sons</dc:publisher>
   96: <dc:date>Created: 1906; Available: 1991</dc:date>
   97: <dc:type>text</dc:type>
   98: <dc:identifier>http://resolver.library.cornell.edu/math/1796949</dc:identifier>
   99: <dc:language>eng</dc:language>
  100: <dc:rights>Public Domain</dc:rights>
  101: </dc:dc>
  102: END
  103: 
  104: open(OUT,'>tmploncapa.xml');
  105: print(OUT <<END);
  106: <?xml version="1.0"?>
  107: <loncapa>
  108: $LONCAPA_metadata
  109: </loncapa>
  110: END
  111: close(OUT);
  112: 
  113: # probably also want to protect dc name-space
  114: open(OUT,'>tmpl2n.xsl');
  115: print(OUT <<END);
  116: <?xml version="1.0"?> 
  117: <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
  118: <xsl:template match="loncapa">
  119: <dc>
  120: <xsl:text>
  121: </xsl:text>
  122: <creator>
  123: <xsl:value-of select="author"/>
  124: </creator>
  125: <xsl:text>
  126: </xsl:text>
  127: <publisher><xsl:value-of select="owner"/></publisher>
  128: <xsl:text>
  129: </xsl:text>
  130: <title><xsl:value-of select="title"/></title>
  131: <xsl:text disable-output-escaping="yes">
  132: &lt;!-- NEED TO IMPLEMENT --&gt;
  133: &lt;!-- converted from LON-CAPA language tag to Dublin Core language tag --&gt;
  134: </xsl:text>
  135: <language><xsl:value-of select="language"/></language>
  136: <xsl:text disable-output-escaping="yes">
  137: &lt;!-- NEED TO IMPLEMENT --&gt;
  138: &lt;!-- converted from LON-CAPA seconds since 1/1/1970 to standard
  139: calendar values --&gt;
  140: </xsl:text>
  141: <date>
  142: Created: <xsl:value-of select="creationdate"/>;
  143: Last revised: <xsl:value-of select="lastrevisiondate"/>
  144: </date>
  145: <xsl:text disable-output-escaping="yes">
  146: &lt;!-- NEED TO IMPLEMENT --&gt;
  147: &lt;!-- allow some sort of mapping to Library of Congress or Dewey Decimal
  148: standard subject mapping --&gt;
  149: </xsl:text>
  150: <subject><xsl:value-of select="subject"/></subject>
  151: <xsl:text>
  152: </xsl:text>
  153: <xsl:text disable-output-escaping="yes">
  154: &lt;!-- NEED TO IMPLEMENT --&gt;
  155: </xsl:text>
  156: <audience>unknown mapping</audience>
  157: <xsl:text>
  158: </xsl:text>
  159: <xsl:text disable-output-escaping="yes">
  160: &lt;!-- NEED TO IMPLEMENT --&gt;
  161: </xsl:text>
  162: <contributor>unknown mapping (coauthors?)</contributor>
  163: <xsl:text>
  164: </xsl:text>
  165: <xsl:text disable-output-escaping="yes">
  166: &lt;!-- NEED TO IMPLEMENT --&gt;
  167: </xsl:text>
  168: <relation>unknown mapping... prerequisite/postrequisite info could go here</relation>
  169: <xsl:text>
  170: </xsl:text>
  171: <xsl:text disable-output-escaping="yes">
  172: &lt;!-- NEED TO IMPLEMENT --&gt;
  173: </xsl:text>
  174: <coverage>unknown mapping</coverage>
  175: <xsl:text>
  176: </xsl:text>
  177: <xsl:text disable-output-escaping="yes">
  178: &lt;!-- NEED TO IMPLEMENT --&gt;
  179: </xsl:text>
  180: <identifier>the gateway url</identifier>
  181: <xsl:text>
  182: </xsl:text>
  183: <xsl:text disable-output-escaping="yes">
  184: &lt;!-- NEED TO IMPLEMENT --&gt;
  185: &lt;!-- probably mapping from LON-CAPA mime typing --&gt;
  186: </xsl:text>
  187: <resourcetype>n/a</resourcetype>
  188: <xsl:text disable-output-escaping="yes">
  189: &lt;!-- NEED TO IMPLEMENT --&gt;
  190: &lt;!-- probably mapping from LON-CAPA copyright --&gt;
  191: </xsl:text>
  192: <rights>n/a</rights>
  193: <description><xsl:value-of select="abstract"/></description>
  194: <xsl:text>
  195: </xsl:text>
  196: # Source
  197: <xsl:text disable-output-escaping="yes">
  198: &lt;!-- NEED TO IMPLEMENT --&gt;
  199: </xsl:text>
  200: <format>software and hardware needed</format>
  201: <xsl:text disable-output-escaping="yes">
  202: &lt;!-- NEED TO IMPLEMENT --&gt;
  203: </xsl:text>
  204: <subjectandkeywords>need to break things into formal "classification" tag to insert keywords</subjectandkeywords>
  205: <xsl:text>
  206: </xsl:text>
  207: </dc>
  208: </xsl:template>
  209: </xsl:stylesheet>
  210: END
  211: close(OUT);
  212: 
  213: # probably also want to protect dc name-space
  214: open(OUT,'>tmpn2l.xsl');
  215: print(OUT <<END);
  216: <?xml version="1.0"?> 
  217: <xsl:stylesheet
  218:   xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0"
  219:   xmlns:external="$namespace"
  220: >
  221: <xsl:template match="/">
  222: <loncapa>
  223: <xsl:text>
  224: </xsl:text>
  225: <xsl:apply-templates select="/*/dc:*"/>
  226: </loncapa>
  227: <xsl:text>
  228: </xsl:text>
  229: </xsl:template>
  230: <xsl:template match="dc:title">
  231: <title>
  232:          <xsl:choose>
  233:            <xsl:when test="function-available('external:plain-text')">
  234:              <xsl:value-of select="external:plain-text(.)"/>
  235:            </xsl:when>
  236:            <xsl:otherwise>
  237:              Function external:plain-text() is not available!
  238:            </xsl:otherwise>
  239:          </xsl:choose>
  240: </title>
  241: <xsl:text>
  242: </xsl:text>
  243: </xsl:template>
  244: <xsl:template match="dc:date">
  245: <date><xsl:value-of select="."/></date>
  246: <xsl:text>
  247: </xsl:text>
  248: </xsl:template>
  249: <xsl:template match="dc:rights">
  250: <copyright><xsl:value-of select="."/></copyright>
  251: <xsl:text>
  252: </xsl:text>
  253: </xsl:template>
  254: <xsl:template match="dc:identifier">
  255: <dc:identifier><xsl:value-of select="."/></dc:identifier>
  256: <xsl:text>
  257: </xsl:text>
  258: </xsl:template>
  259: </xsl:stylesheet>
  260: END
  261: close(OUT);
  262: 
  263: # ---------------------------------- LON-CAPA to NSDL (Dublic Core PLUS format)
  264: my $compiled = $tr->compile_stylesheet_file("tmpl2n.xsl");
  265: my $parsed = $tr->parse_file("tmploncapa.xml");
  266: my $dest_file="l2n.xml";
  267: $tr->transform_to_file($parsed, $compiled, $dest_file)
  268:     or die $tr->errstr;
  269: 
  270: # ---------------------------------- NSDL (Dublic Core PLUS format) to LON-CAPA
  271: my $compiled = $tr->compile_stylesheet_file("tmpn2l.xsl");
  272: my $parsed = $tr->parse_file("tmpdc.xml");
  273: my $dest_file="n2l.xml";
  274: $tr->transform_to_file($parsed, $compiled, $dest_file)
  275:     or die $tr->errstr;
  276: 
  277: # ---------------------------------- test
  278: my $compiled = $tr->compile_stylesheet_file("test1.xsl");
  279: my $parsed = $tr->parse_file("test1.xml");
  280: my $dest_file="test1out.xml";
  281: $tr->transform_to_file($parsed, $compiled, $dest_file)
  282:     or die $tr->errstr;

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>