sparklemotion/nokogiri

JRuby XSLT failure

Open

#1.751 aberto em 22 de abr. de 2018

Ver no GitHub
 (6 comments) (0 reactions) (0 assignees)Ruby (806 forks)batch import
help wantedneeds/researchplatform/jruby

Métricas do repositório

Stars
 (5.615 stars)
Métricas de merge de PR
 (Nenhuma PRs mesclada em 30d)

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

Guia do colaborador