sparklemotion/nokogiri

JRuby XSLT failure

Open

#1 751 ouverte le 22 avr. 2018

Voir sur GitHub
 (6 commentaires) (0 réactions) (0 assignés)Ruby (806 forks)batch import
help wantedneeds/researchplatform/jruby

Métriques du dépôt

Stars
 (5 615 stars)
Métriques de merge PR
 (Aucune PR mergée en 30 j)

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

Guide contributeur