Commits

Toby Inkster  committed bc165a9

XSLT2 support in XML-GRDDL; this needs XSLT-Saxon-XSLT2 to provide output media-type info, so a change to that dist too.

  • Participants
  • Parent commits 9575ecf

Comments (0)

Files changed (18)

 Bug tracker:  <http://rt.cpan.org/Dist/Display.html?Queue=XML-GRDDL>
 Maintainer:   Toby Inkster <mailto:tobyink@cpan.org>
 
+0.002 [2010-07-19]
+ - (Addition) Optional XSLT 2.0 support via XML::Saxon::XSLT2.
+
 0.001 [2010-07-14] # Original version
 
 	rdfs:comment    "Forked from Swignition."@en ;
 	rdfs:seeAlso    <http://buzzword.org.uk/swignition/#swignition> .
 
+my:v_0-002
+	a               :Version ;
+	dc:issued       "2010-07-19"^^xsd:date ;
+	:revision       "0.002"^^xsd:string ;
+	:file-release   <http://backpan.cpan.org/authors/id/T/TO/TOBYINK/XML-GRDDL-0.002.tar.gz> ;
+	dcs:changeset [
+		dcs:versus my:v_0-001 ;
+		dcs:item   [ rdfs:label "Optional XSLT 2.0 support via XML::Saxon::XSLT2."@en ; a dcs:Addition ]
+		] .
+
 #############################################################
 
 my:project
 	:tester         toby:i ;
 	:created        "2010-07-14"^^xsd:date ;
 	:license        <http://dev.perl.org/licenses/> ;
-	:release        my:v_0-001 .
+	:release        my:v_0-001 , my:v_0-002 .
 
 #############################################################
 
-<?xml version="1.0" encoding="utf-8"?>
-<rdf:RDF
-   xmlns:dc="http://purl.org/dc/terms/"
-   xmlns:dcs="http://ontologi.es/doap-changeset#"
-   xmlns:foaf="http://xmlns.com/foaf/0.1/"
-   xmlns:my="http://purl.org/NET/cpan-uri/dist/XML-GRDDL/"
-   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
-   xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
-   xmlns:toby="http://tobyinkster.co.uk/#"
-   xmlns:xsd="http://www.w3.org/2001/XMLSchema#"
-   xmlns="http://usefulinc.com/ns/doap#">
-  <rdf:Description rdf:about="file:///home/tai/src/perlmods/XML-GRDDL/Changes.ttl">
-    <dc:creator rdf:resource="http://tobyinkster.co.uk/#i"/>
-    <dc:description xml:lang="en">Revision history for Perl extension XML::GRDDL.</dc:description>
-    <dc:subject rdf:resource="http://purl.org/NET/cpan-uri/dist/XML-GRDDL/project"/>
-    <dc:title>Changes</dc:title>
-  </rdf:Description>
-  <Version rdf:about="http://purl.org/NET/cpan-uri/dist/XML-GRDDL/v_0-001">
-    <dc:issued rdf:datatype="http://www.w3.org/2001/XMLSchema#date">2010-07-14</dc:issued>
-    <file-release rdf:resource="http://backpan.cpan.org/authors/id/T/TO/TOBYINK/XML-GRDDL-0.001.tar.gz"/>
-    <revision rdf:datatype="http://www.w3.org/2001/XMLSchema#string">0.001</revision>
-    <rdfs:comment xml:lang="en">Forked from Swignition.</rdfs:comment>
-    <rdfs:label xml:lang="en">Original version</rdfs:label>
-    <rdfs:seeAlso rdf:resource="http://buzzword.org.uk/swignition/#swignition"/>
-  </Version>
-  <Project rdf:about="http://purl.org/NET/cpan-uri/dist/XML-GRDDL/project">
-    <bug-database rdf:resource="http://rt.cpan.org/Dist/Display.html?Queue=XML-GRDDL"/>
-    <created rdf:datatype="http://www.w3.org/2001/XMLSchema#date">2010-07-14</created>
-    <developer rdf:resource="http://tobyinkster.co.uk/#i"/>
-    <documenter rdf:resource="http://tobyinkster.co.uk/#i"/>
-    <download-page rdf:resource="http://search.cpan.org/dist/XML-GRDDL/"/>
-    <homepage rdf:resource="http://search.cpan.org/dist/XML-GRDDL/"/>
-    <license rdf:resource="http://dev.perl.org/licenses/"/>
-    <maintainer rdf:resource="http://tobyinkster.co.uk/#i"/>
-    <name>XML-GRDDL</name>
-    <programming-language>Perl</programming-language>
-    <release rdf:resource="http://purl.org/NET/cpan-uri/dist/XML-GRDDL/v_0-001"/>
-    <repository>
-      <SVNRepository>
-        <browse rdf:resource="http://goddamn.co.uk/viewvc/perlmods/XML-GRDDL/"/>
-      </SVNRepository>
-    </repository>
-    <shortdesc xml:lang="en">transform XML and XHTML to RDF</shortdesc>
-    <tester rdf:resource="http://tobyinkster.co.uk/#i"/>
-  </Project>
-  <foaf:Person rdf:about="http://tobyinkster.co.uk/#i">
-    <ns1:sameAs xmlns:ns1="http://www.w3.org/2002/07/owl#" rdf:resource="http://purl.org/NET/cpan-uri/person/tobyink"/>
-    <foaf:homepage rdf:resource="http://tobyinkster.co.uk/"/>
-    <foaf:mbox rdf:resource="mailto:tobyink@cpan.org"/>
-    <foaf:name>Toby Inkster</foaf:name>
-    <foaf:page rdf:resource="http://search.cpan.org/~tobyink/"/>
-  </foaf:Person>
-</rdf:RDF>
 lib/XML/GRDDL/Transformation/RDF_EASE.pm
 lib/XML/GRDDL/Transformation/RDF_EASE/Selector.pm
 lib/XML/GRDDL/Transformation/XSLT_1.pm
+lib/XML/GRDDL/Transformation/XSLT_2.pm
   directory:
     - inc
     - t
+recommends:
+  XML::Saxon::XSLT2: 0.003
 requires:
   CSS: 0
   CSS::Parse::PRDGrammar: 0
   Scalar::Util: 0
   URI: 1.30
   URI::Escape: 0
-  XML::LibXML: 0
+  XML::LibXML: 1.60
   XML::LibXSLT: 0
   common::sense: 0
   perl: 5.8.0
   homepage: http://search.cpan.org/dist/XML-GRDDL/
   license: http://dev.perl.org/licenses/
   repository: http://goddamn.co.uk/viewvc/perlmods/XML-GRDDL/
-version: 0.001
+version: 0.002
 author              'Toby Inkster <tobyink@cpan.org>';
 license             'perl';
 
-test_requires       'Test::More' => '0.61';
-
 requires            'Carp'               => '1.00';
 requires            'common::sense'      => 0;
 requires            'CSS'                => 0;
 requires            'RDF::RDFa::Parser'  => '1.09_10';
 requires            'RDF::Trine'         => '0.124';
 requires            'Scalar::Util'       => 0;
-requires            'XML::LibXML'        => '1.60';
+test_requires       'Test::More'         => '0.61';
 requires            'URI'                => '1.30';
 requires            'URI::Escape'        => 0;
-requires            'XML::LibXML'        => 0;
+requires            'XML::LibXML'        => '1.60';
 requires            'XML::LibXSLT'       => 0;
-
-# install_script 'fingerw';
+recommends          'XML::Saxon::XSLT2'  => '0.003';
 
 resources(
 	'homepage'   => "http://search.cpan.org/dist/$dist/",

File XML-GRDDL-0.002.tar.gz

Binary file added.
 
 my $grddl = XML::GRDDL->new();
 my $data  = {};
-foreach my $url (qw(http://localhost/test/grddl/document.html http://localhost/test/grddl/document2.html http://localhost/test/grddl/ease.html))
+foreach my $url (qw(http://localhost/test/grddl/document.html
+	http://localhost/test/grddl/document2.html
+	http://localhost/test/grddl/ease.html
+	http://www.w3.org/TR/grddl-primer/hotel-data.html))
 {
 	print "#### URL: $url\n";
 	my $r = $grddl->data(get($url), $url, force_rel=>1, metadata=>1);

File lib/XML/GRDDL.pm

 use XML::GRDDL::Transformation;
 use XML::LibXML;
 
-our $VERSION = '0.001';
+our $VERSION = '0.002';
 
 sub new
 {

File lib/XML/GRDDL/External.pm

 
 use XML::GRDDL;
 
-our $VERSION = '0.001';
+our $VERSION = '0.002';
 
 sub new
 {

File lib/XML/GRDDL/Namespace.pm

 use RDF::Trine qw[iri];
 use Scalar::Util qw[blessed];
 
-our $VERSION = '0.001';
+our $VERSION = '0.002';
 
 # hard-code certain namespaces to skip...
 our @ignore = (

File lib/XML/GRDDL/Profile.pm

 use RDF::Trine qw[iri];
 use Scalar::Util qw[blessed];
 
-our $VERSION = '0.001';
+our $VERSION = '0.002';
 
 # hard-code certain profiles to skip...
 our @ignore = (

File lib/XML/GRDDL/Transformation.pm

 use common::sense;
 use base qw[XML::GRDDL::External];
 
+use XML::GRDDL::Transformation::RDF_EASE;
 use XML::GRDDL::Transformation::XSLT_1;
-use XML::GRDDL::Transformation::RDF_EASE;
+BEGIN { eval 'use XML::GRDDL::Transformation::XSLT_2;'; }
 
-our $VERSION = '0.001';
+our $VERSION = '0.002';
 
 sub new
 {
 	if ($response->header('content-type') =~ m#xslt?#i
 	||  $response->content =~ m#http://www.w3.org/1999/XSL/Transform#)
 	{
-		return bless $self, 'XML::GRDDL::Transformation::XSLT_1';
+		if ( XML::GRDDL::Transformation::XSLT_2->can('transform') )
+			{ return bless $self, 'XML::GRDDL::Transformation::XSLT_2'; }
+		else
+			{ return bless $self, 'XML::GRDDL::Transformation::XSLT_1'; }
 	}
 	elsif ($response->header('content-type') =~ /text\/(css|x\-rdf\+css)/i)
 	{

File lib/XML/GRDDL/Transformation/RDF_EASE.pm

 use Scalar::Util qw[blessed];
 use XML::GRDDL::Transformation::RDF_EASE::Functional qw[:standard];
 
-our $VERSION = '0.001';
+our $VERSION = '0.002';
 
 sub transform
 {

File lib/XML/GRDDL/Transformation/RDF_EASE/Functional.pm

 use Exporter;
 use XML::LibXML;
 
-our $VERSION = '0.001';
+our $VERSION = '0.002';
 
 our @EXPORT_OK = qw(&rdfease_to_rdfa &parse_sheet &parse_value &bnode_for_element &rule_matches_node);
 our %EXPORT_TAGS = (

File lib/XML/GRDDL/Transformation/RDF_EASE/Selector.pm

 use 5.008;
 use common::sense;
 
-our $VERSION = '0.001';
+our $VERSION = '0.002';
 
 sub specificity
 {

File lib/XML/GRDDL/Transformation/XSLT_1.pm

 use XML::LibXML;
 use XML::LibXSLT;
 
-our $VERSION = '0.001';
+our $VERSION = '0.002';
 
 sub transform
 {

File lib/XML/GRDDL/Transformation/XSLT_2.pm

+package XML::GRDDL::Transformation::XSLT_2;
+
+use 5.008;
+use common::sense;
+use base qw[XML::GRDDL::Transformation];
+
+use Scalar::Util qw[blessed];
+use XML::LibXML;
+use XML::Saxon::XSLT2 '0.003';
+
+our $VERSION = '0.002';
+
+sub transform
+{
+	my ($self, $input) = @_;
+	
+	# Use just documentElement because passing a DOCTYPE to Saxon can be fatal!
+	if (blessed($input) && $input->isa('XML::LibXML::Document'))
+	{
+		$input = $input->documentElement->toString;
+	}
+	
+	my $response = $self->{'response'};
+	
+	my ($output, $type);
+	local $@ = undef;
+	eval {
+		my $xslt = XML::Saxon::XSLT2->new($response->decoded_content, ''.$response->base);
+		$type    = $xslt->media_type;
+		$output  = $xslt->transform($input);
+	};
+
+	$type ||= ($output =~ m!<http://!) ? 'text/turtle' : 'application/rdf+xml';
+
+	return ($output, $type) if wantarray;
+	return $output;
+}
+
+1;
+
+__END__
+
+=head1 NAME
+
+XML::GRDDL::Transformation::XSLT_2 - represents an XSLT 2.0 transformation
+
+=head1 DESCRIPTION
+
+Implements XSLT transformations. Uses L<XML::Saxon::XSLT2>.
+
+XML::GRDDL::Transformation loads this module in an eval block, so
+if you don't have XML::Saxon::XSLT2 then things shouldn't break too
+badly - however you'll only be able to use XSLT 1.0.
+
+=head1 SEE ALSO
+
+L<XML::GRDDL>, L<XML::GRDDL::Transformation>.
+
+=head1 AUTHOR
+
+Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
+
+=head1 COPYRIGHT
+
+Copyright 2010 Toby Inkster
+
+This library is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.