#!/usr/bin/perl -w use CGI; use XML::LibXSLT; use XML::LibXML; use URI; # for parsing URL syntax. not curently used use LWP::Simple; # for grabbing url. not currently used, but might need the "get" method for URIs # Get the CGI input variables my $query = new CGI; my $project_id = $query->param('project_id'); my $project_file = 'project.' . "$project_id" . '.xml'; # instantiate objects for reading XML and transforming my $parser = XML::LibXML->new(); my $xslt = XML::LibXSLT->new(); # set default paths: my $xslt_path = '../lib/xslt'; my $project_xml_path = '../lib/xml/research/projects'; # my $XSLT_doc = 'http://amble.lternet.edu:8080/exist/rest/db/projects/util/xslt/sbcProjectDescription.xsl'; # my $XSLT_doc = 'http://sbc.lternet.edu/~mob/share/XSL/sbcProjectDescription_wrapper.xsl'; my $XSLT_doc = "${xslt_path}/projects/sbcProjectDescription_wrapper.xsl"; # uses a static file for now. later, a webservice with only the project id.. # my $EML_project_xml = "http://sbc.lternet.edu/~mob/share/XML/${project_file}"; my $EML_project_xml = "${project_xml_path}/${project_file}"; ## parse 2 XML files: the eml project and the xslt # per: http://search.cpan.org/~pajas/XML-LibXML-1.69/ (what penguin runs) my $source = $parser->parse_file( "$EML_project_xml" ); my $style_doc = $parser->parse_file("${XSLT_doc}"); # this syntax for 1.7 (current as of march 2010, but penguin is out of date) # my $source = XML::LibXML->load_xml(location => 'test.xml'); # my $style_doc = XML::LibXML->load_xml(location=>'test_person.xsl', no_cdata=>1); my $stylesheet = $xslt->parse_stylesheet($style_doc); my $results = $stylesheet->transform($source); print "Content-type: text/html\n\n"; # per http://search.cpan.org/~msergeant/XML-LibXSLT-1.58/LibXSLT.pm print $stylesheet->output_string($results); # 1.7 version #print $stylesheet->output_as_bytes($results);