Annotation of nsdl/prototypes/metadata_convert.pl, revision 1.4

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

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