Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
require 'rubygems'
require 'nokogiri'
def xpath_values doc, for_each_xpath, value_xpath
xslt_str =
%{<xsl:stylesheet version="1.0"
<!-- Not well-formed: -->
<xsl:template match="/"/>
<xsl:for-each select="#{for_each_xpath}">
<xsl:value-of select="#{value_xpath}"/>
xslt = Nokogiri::XSLT.parse(xslt_str)
# I think this should throw an error for the well-formedness error
# in the XSLT stylesheet, but there should be no segfault.
result_doc = xslt.transform(doc)
doc = Nokogiri::XML('<foo id="a"><b id="b"/></foo>')
p xpath_values(doc,"//*", "@id")
# I get this:
$ ruby noko.rb
compilation error: element for-each
element for-each only allowed within a template, variable or param
compilation error: element value-of
element value-of only allowed within a template, variable or param
Found a top-level element values with null namespace URI
noko.rb:23: [BUG] Segmentation fault
ruby 1.8.6 (2007-03-13) [i686-linux]
$ sudo gem list --local nokogiri
*** LOCAL GEMS ***
nokogiri (1.2.3)
$ dpkg -s libxml2-dev | grep Version
Version: 2.6.32.dfsg-5ubuntu4
$ dpkg -s libxslt1-dev | grep Version
Version: 1.1.24-2ubuntu2
$ uname -a
Linux thinkpad-ubuntu 2.6.28-11-generic #42-Ubuntu SMP [...] i686 GNU/Linux
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.