sparklemotion/nokogiri

JRuby XSLT failure

Open

#1751 opened on Apr 22, 2018

View on GitHub
 (6 comments) (0 reactions) (0 assignees)Ruby (5,615 stars) (806 forks)batch import
help wantedneeds/researchplatform/jruby

Description

Using XSLT to write JSON, my program either hangs or gives an inscrutable error message. The same XML/XSLT processes fine with xsltproc and with MRI.

I created this short program to demonstrate the problem:

#!/usr/bin/env ruby -w
require 'nokogiri'

doc = Nokogiri::XML('<g>Greetings</g>')
xslt = Nokogiri::XSLT(<<-STYLESHEET
  <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
    <xsl:output method="text" omit-xml-declaration="yes"/>
  </xsl:stylesheet>
  STYLESHEET
  )
puts xslt.transform(doc)

The result is

RuntimeError: org.w3c.dom.DOMException: HIERARCHY_REQUEST_ERR: An attempt was made to insert a node where it is not permitted. 
  transform at nokogiri/XsltStylesheet.java:231
     <main> at exe/test.rb:11

When I run a similar transformation using a larger XML and XSLT, the program hangs indefinitely. For that, the XML and XSLT are attached and the the program is

#!/usr/bin/env ruby -w
require 'nokogiri'

doc = Nokogiri::HTML('toc2json.html')
xslt = Nokogiri::XSLT('toc2json.xsl')
File.open('toc2json.json', 'w') do |file|
  file.write xslt.transform(doc)
end

toc2json.zip

Contributor guide