I'm not sure this is the best way, but editing the source in my RVM environment, followed by a minimized build_all, allowed me to remove the exception handling. My modified XsltStylesheet.java :
@JRubyMethod
public IRubyObject serialize(ThreadContext context, IRubyObject doc) throws IOException, TransformerException {
XmlDocument xmlDoc = (XmlDocument) doc;
TransformerImpl transformer = (TransformerImpl) this.sheet.newTransformer();
ByteArrayOutputStream writer = new ByteArrayOutputStream();
StreamResult streamResult = new StreamResult(writer);
SerializationHandler serializationHandler = transformer.createSerializationHandler(streamResult);
serializationHandler.serialize(xmlDoc.getNode());
return context.getRuntime().newString(writer.toString());
}
@JRubyMethod(rest = true, required=1, optional=2)
public IRubyObject transform(ThreadContext context, IRubyObject[] args) throws TransformerException, IOException {
Ruby runtime = context.getRuntime();
System.out.println("in transform");
argumentTypeCheck(runtime, args[0]);
System.out.println("before listener");
// NokogiriXsltErrorListener elistener = new NokogiriXsltErrorListener();
System.out.println("before dom");
DOMSource domSource = new DOMSource(((XmlDocument) args[0]).getDocument());
final DOMResult result; String stringResult = null;
System.out.println("try transform");
result = tryXsltTransformation(context, args, domSource, null); // DOMResult
if (stringResult == null) {
return createDocumentFromDomResult(context, runtime, result);
} else {
return createDocumentFromString(context, runtime, stringResult);
}
}
private DOMResult tryXsltTransformation(ThreadContext context, IRubyObject[] args, DOMSource domSource, NokogiriXsltErrorListener elistener) throws TransformerException {
Transformer transf = sheet.newTransformer();
transf.reset();
// transf.setErrorListener(elistener);
if (args.length > 1) {
addParametersToTransformer(context, transf, args[1]);
}
DOMResult result = new DOMResult();
transf.transform(domSource, result);
return result;
}
Here is my build-all script:
#! /usr/bin/env bash
#
# script to build gems for all relevant platforms:
# - MRI et al (standard gem)
# - windows (x86-mingw32 and x64-mingw32)
# - jruby
#
# Load RVM into a shell session *as a function*
if [[ -s "$HOME/.rvm/scripts/rvm" ]] ; then
source "$HOME/.rvm/scripts/rvm"
elif [[ -s "/usr/local/rvm/scripts/rvm" ]] ; then
source "/usr/local/rvm/scripts/rvm"
else
echo "ERROR: An RVM installation was not found.\n"
fi
set -o errexit
rm -rf tmp pkg
bundle exec rake clean clobber
# holding pen
rm -rf gems
mkdir -p gems
# windows
# MRI
# jruby
bundle exec rake clean clobber
bundle exec rake generate
gem install bundler --conservative
bundle install --quiet --local || bundle install
bundle exec rake gem
cp -v pkg/nokogiri*java.gem gems
This produced the output:
...
try transform
file:///Users/jeff/Documents/BlueSageSource/plus/dummy.xsl; Line #0; Column #0; org.apache.xpath.objects.XRTreeFrag cannot be cast to org.apache.xpath.objects.XNodeSet
file:///Users/jeff/Documents/BlueSageSource/plus/dummy.xsl; Line #0; Column #0; java.lang.NullPointerException
The 'cannot be cast' message led me to other information that indicates that Nokogiri does not support XSLT 2. This is disappointing, not so much because of the limitation, but because it is not well documented, and failing with a null pointer exception is at best unfriendly. I think we have enough information to create a minimal failing case to file as a request for enhancement.
references:
Nokogiri does not intend to support XSLT 2
Nokogiri does not support XSLT 2