I'm trying to get a simple XSLT 2.0 transformation running using perl and XML::Saxon::XSLT2. Here's what i've tried so far:
test.xhtml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>My Title</title>
</head>
<body>
<p>My Content</p>
</body>
</html>
test.xslt:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
version="2.0">
<xsl:template match="/">
<xsl:apply-templates />
</xsl:template>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
xslttest.pl:
use strictures;
use diagnostics;
use XML::Saxon::XSLT2;
use XML::LibXML;
my $parser = XML::LibXML->new;
my $xsl = 'test.xslt';
my $xslt = $parser->load_xml( location => $xsl );
my $dom = $parser->load_xml( location => 'test.xhtml' );
my $trans = XML::Saxon::XSLT2->new($xslt);
my $output = $trans->transform( $dom, 'xhtml' );
print $output;
Output of locate saxon9he.jar
:
/usr/local/share/java/saxon9he.jar
/usr/share/java/saxon9he.jar
Now, if i run perl xslttest.pl
, i get:
Uncaught exception from user code:
A problem was encountered while attempting to compile and install your Inline
Java code. The command that failed was:
"/usr/lib/jvm/default-java/bin/javac" -deprecation -d "/tmp/perltest/_Inline/lib/auto/XML/Saxon/XSLT2_dbc0" Transformer.java > cmd.out 2>&1
The build directory was:
/tmp/perltest/_Inline/build/XML/Saxon/XSLT2_dbc0
The error message was:
Transformer.java:1: error: package net.sf.saxon.s9api does not exist
import net.sf.saxon.s9api.*;
^
Transformer.java:29: error: cannot find symbol
private XsltExecutable xslt;
^
symbol: class XsltExecutable
location: class Transformer
Transformer.java:30: error: cannot find symbol
private Processor proc;
^
symbol: class Processor
location: class Transformer
Transformer.java:31: error: cannot find symbol
private HashMap<String, XdmAtomicValue> params;
^
(...)
Perl version (result of perl -v
):
This is perl 5, version 18, subversion 2 (v5.18.2) built for x86_64-linux-gnu-thread-multi
(with 41 registered patches, see perl -V for more detail)
(...)
Why does the transformation fail? It seems that Inline::Java fails to compile the required code (???), but how to avoid this?
EDIT:
The net.sf.saxon.s9api.*
classes are provided by the saxon9he.jar
itself:
$ jar tvf /usr/share/java/saxon9he.jar | grep net.sf.saxon.s9api
0 Wed Aug 06 10:34:58 CEST 2014 net/sf/saxon/s9api/
1805 Wed Aug 06 10:34:58 CEST 2014 net/sf/saxon/s9api/Axis.class
302 Wed Aug 06 10:34:58 CEST 2014 net/sf/saxon/s9api/BuildingContentHandler.class
421 Wed Aug 06 10:34:58 CEST 2014 net/sf/saxon/s9api/BuildingStreamWriter.class
1207 Wed Aug 06 10:34:58 CEST 2014 net/sf/saxon/s9api/BuildingStreamWriterImpl.class
2025 Wed Aug 06 10:34:58 CEST 2014 net/sf/saxon/s9api/ConstructedItemType.class
1130 Wed Aug 06 10:34:58 CEST 2014 net/sf/saxon/s9api/DOMDestination.class
303 Wed Aug 06 10:34:58 CEST 2014 net/sf/saxon/s9api/Destination.class
1367 Wed Aug 06 10:34:58 CEST 2014 net/sf/saxon/s9api/DocumentBuilder$BuildingContentHandlerImpl.class
8981 Wed Aug 06 10:34:58 CEST 2014 net/sf/saxon/s9api/DocumentBuilder.class
455 Wed Aug 06 10:34:58 CEST 2014 net/sf/saxon/s9api/ExtensionFunction.class
(...)
Your script works for me, and produces the following output:
<?xml version="1.0" encoding="UTF-8"?><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>My Title</title>
</head>
<body>
<p>My Content</p>
</body>
</html>
(Though it's not exactly fast. I'd forgotten how slow Inline::Java stuff was.)
I have the following installed (on Ubuntu 14.04):
/usr/lib/jvm/java-7-openjdk-i386/
/usr/share/java/saxon9he.jar
Do you have similar versions? Did you install Inline::Java correctly (you need to set the JAVA_HOME
environment variable). Did you run the tests that came with it? Did they pass? (If you used a CPAN client to install Inline::Java, it would normally run the test cases and only install the module if it passed, unless you explicitly override this behaviour.)
Similarly, did you run the test case that comes with XML::Saxon::XSLT2? Did it pass? (Because it does something fairly similar to your test script.)
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다