[AMF-talk] xsl

Thomas Krichel amf-talk@lists.openlib.org
Fri, 9 Aug 2002 12:12:44 -0500


  Hi,

  I am playing around with amf2dc via xsl and I got it to run!

  Here is the perl script

#!/usr/bin/perl

$home=$ENV{'HOME'};

$testfile="$home/oai/lib/amf/RePEc/sur/surrec/9601.xml";
$sheet="$home/oai/etc/amf2oai_dc.xsl";

use XML::LibXSLT;
use XML::LibXML;

my $parser = XML::LibXML->new();
my $xslt = XML::LibXSLT->new();

my $source = $parser->parse_file($testfile);
my $style_doc = $parser->parse_file($sheet);

my $stylesheet = $xslt->parse_stylesheet($style_doc);

my $results = $stylesheet->transform($source);

print $stylesheet->output_string($results);

  of course, this is just a prove of concept script. Note
  that I can transform many source docs with the 
  same parsed stylesheet. That should be handy for  
  performance. 

  Here is a (shortened) version of the stylesheet

?xml version="1.0" encoding="UTF-8" ?>

<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                               xmlns:oai_dc="http://purl.org/dc/elements/1.1/"
                               xmlns:amf="http://amf.openlib.org"
                         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">

<xsl:output method="xml" indent="yes"/>

<!-- by thomas krichel http://openlib.org/home/krichel, verry preliminary -->

<xsl:template match="/">
<oai_dc:dc xsi:schemaLocation="http://purl.org/dc/elements/2.0/oai_dc http://ww\
w.openarchives.org/OAI/2.0/oai_dc.xsd">
<xsl:apply-templates/>
</oai_dc:dc>
</xsl:template>

<!--- creator -->
<xsl:template match="amf:text/amf:hasauthor/amf:person/amf:name">
<oai_dc:creator>
<xsl:value-of select="."/>
</oai_dc:creator>
</xsl:template>

<!-- stuff deleted -->

<!-- remove the default printing of text-->
<xsl:template match="text()">
</xsl:template>

</xsl:stylesheet>

  It runs like a charm! Way cool! Hurray!!!

  I will put the stuff into 

  openlib@openlib.org/share/thomas

  Simeon, if you have things to share, why not put it in

  openlib@openlib.org/share/simeon

  for me to rsync?

  I am a happy hacker. And I have a date with a lady a bit
  later :-)


  Cheers,

  Thomas Krichel                                   mailto:krichel@openlib.org
                                              http://openlib.org/home/krichel
                                          RePEc:per:1965-06-05:thomas_krichel