sparklemotion/nokogiri

JRuby XSLT failure

Open

#1,751 建立於 2018年4月22日

在 GitHub 查看
 (6 留言) (0 反應) (0 負責人)Ruby (5,615 star) (806 fork)batch import
help wantedneeds/researchplatform/jruby

描述

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

貢獻者指南