Trying to use the htmltoword gem, v. 0.4.4, to generate a Word document from an HTML string on JRuby 1.7.21, Oracle JDK 1.8.0_45, and Nokogiri gem 1.6.6.2.
module Integrator
module Export
class Docx
require 'htmltoword'
def export
Htmltoword::Document.create('<html><head></head><body><p>Hello</p></body></html>')
end
end
end
end
It fails when trying to parse the XSLT stylesheet numbering.xslt, with the unhelpful error message
RuntimeError (could not parse xslt stylesheet):
lib/integrator/export/docx.rb:7:in `export'
It is actually failing on the first line of Htmltoword::Document::transform_and_replace when trying to open the file with Nokogiri. When running on JRuby, Nokogiri uses Apache Xerces to parse XSL files rather than libxslt, and from what I understand, libxslt is more forgiving about bad stylesheets.
I'm lacking any good XSLT editors. I did try to run this in Eclipse and received the following error there:
Cannot convert data-type 'void' to 'reference'.
at com.sun.org.apache.xalan.internal.xsltc.compiler.CastExpr.typeCheck(CastExpr.java:188)
at com.sun.org.apache.xalan.internal.xsltc.compiler.CastExpr.<init>(CastExpr.java:143)
at com.sun.org.apache.xalan.internal.xsltc.compiler.WithParam.typeCheck(WithParam.java:146)
at com.sun.org.apache.xalan.internal.xsltc.compiler.SyntaxTreeNode.typeCheckContents(SyntaxTreeNode.java:493)
at com.sun.org.apache.xalan.internal.xsltc.compiler.CallTemplate.typeCheck(CallTemplate.java:98)
at com.sun.org.apache.xalan.internal.xsltc.compiler.SyntaxTreeNode.typeCheckContents(SyntaxTreeNode.java:493)
at com.sun.org.apache.xalan.internal.xsltc.compiler.LiteralElement.typeCheck(LiteralElement.java:201)
at com.sun.org.apache.xalan.internal.xsltc.compiler.SyntaxTreeNode.typeCheckContents(SyntaxTreeNode.java:493)
at com.sun.org.apache.xalan.internal.xsltc.compiler.When.typeCheck(When.java:93)
at com.sun.org.apache.xalan.internal.xsltc.compiler.SyntaxTreeNode.typeCheckContents(SyntaxTreeNode.java:493)
at com.sun.org.apache.xalan.internal.xsltc.compiler.Instruction.typeCheck(Instruction.java:41)
at com.sun.org.apache.xalan.internal.xsltc.compiler.SyntaxTreeNode.typeCheckContents(SyntaxTreeNode.java:493)
at com.sun.org.apache.xalan.internal.xsltc.compiler.Template.typeCheck(Template.java:295)
at com.sun.org.apache.xalan.internal.xsltc.compiler.SyntaxTreeNode.typeCheckContents(SyntaxTreeNode.java:493)
at com.sun.org.apache.xalan.internal.xsltc.compiler.Stylesheet.typeCheck(Stylesheet.java:657)
at com.sun.org.apache.xalan.internal.xsltc.compiler.Parser.createAST(Parser.java:411)
at com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC.compile(XSLTC.java:486)
at com.sun.org.apache.xalan.internal.xsltc.compiler.XSLTC.compile(XSLTC.java:571)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTemplates(TransformerFactoryImpl.java:977)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformer(TransformerFactoryImpl.java:791)
at com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl.newTransformerHandler(TransformerFactoryImpl.java:1099)
at org.eclipse.wst.xsl.jaxp.debug.invoker.internal.JAXPSAXProcessorInvoker.addStylesheet(JAXPSAXProcessorInvoker.java:137)
at org.eclipse.wst.xsl.jaxp.debug.invoker.internal.JAXPSAXProcessorInvoker.addStylesheet(JAXPSAXProcessorInvoker.java:128)
at org.eclipse.wst.xsl.jaxp.debug.invoker.PipelineDefinition.addStyleSheet(PipelineDefinition.java:161)
at org.eclipse.wst.xsl.jaxp.debug.invoker.PipelineDefinition.configure(PipelineDefinition.java:152)
at org.eclipse.wst.xsl.jaxp.debug.invoker.internal.Main.main(Main.java:72)
14:46:58,596 FATAL [main] Main - Error with stylesheet: file:/Users/snelson/workspaces/xslt/numbering.xslt
org.eclipse.wst.xsl.jaxp.debug.invoker.internal.ConfigurationException: Error with stylesheet: file:/Users/snelson/workspaces/xslt/numbering.xslt
at org.eclipse.wst.xsl.jaxp.debug.invoker.PipelineDefinition.addStyleSheet(PipelineDefinition.java:163)
at org.eclipse.wst.xsl.jaxp.debug.invoker.PipelineDefinition.configure(PipelineDefinition.java:152)
at org.eclipse.wst.xsl.jaxp.debug.invoker.internal.Main.main(Main.java:72)
But I'm still not sure exactly where the problem lies.
I do know it works with JRuby, as the project I used it on required Encrypted documents and password protection, something only possible with JRuby and POI, with this GEM doing the initial grunt work.
Trying to use the htmltoword gem, v. 0.4.4, to generate a Word document from an HTML string on JRuby 1.7.21, Oracle JDK 1.8.0_45, and Nokogiri gem 1.6.6.2.
It fails when trying to parse the XSLT stylesheet
numbering.xslt
, with the unhelpful error messageIt is actually failing on the first line of
Htmltoword::Document::transform_and_replace
when trying to open the file with Nokogiri. When running on JRuby, Nokogiri uses Apache Xerces to parse XSL files rather than libxslt, and from what I understand, libxslt is more forgiving about bad stylesheets.I'm lacking any good XSLT editors. I did try to run this in Eclipse and received the following error there:
But I'm still not sure exactly where the problem lies.