diff --git a/.gitignore b/.gitignore index 4c59702478..9c54338f67 100644 --- a/.gitignore +++ b/.gitignore @@ -14,4 +14,5 @@ mkmf.log cross tags stash +.rake_tasks diff --git a/ext/nokogiri/extconf.rb b/ext/nokogiri/extconf.rb index 8230da87f7..c2d1caf785 100644 --- a/ext/nokogiri/extconf.rb +++ b/ext/nokogiri/extconf.rb @@ -34,7 +34,13 @@ '/opt/local/lib', '/usr/local/lib', '/usr/lib' - ) + ) + find_library('exslt', 'exsltFuncRegister', + LIBDIR, + '/opt/local/lib', + '/usr/local/lib', + '/usr/lib' + ) end @@ -70,6 +76,14 @@ ) abort "need libxslt" end + unless find_header('libexslt/exslt.h', + INCLUDEDIR, + '/usr/include', + '/opt/local/include', + '/usr/local/include' + ) + abort "need libxslt" + end version = try_constant('LIBXML_VERSION', 'libxml/xmlversion.h') end diff --git a/ext/nokogiri/xslt_stylesheet.c b/ext/nokogiri/xslt_stylesheet.c index 8882979ff5..5250ad4e21 100644 --- a/ext/nokogiri/xslt_stylesheet.c +++ b/ext/nokogiri/xslt_stylesheet.c @@ -3,6 +3,7 @@ #include #include #include +#include static void dealloc(xsltStylesheetPtr doc) { @@ -22,6 +23,7 @@ static VALUE parse_stylesheet_doc(VALUE klass, VALUE xmldocobj) xmlDocPtr xml ; xsltStylesheetPtr ss ; Data_Get_Struct(xmldocobj, xmlDoc, xml); + exsltRegisterAll(); ss = xsltParseStylesheetDoc(xmlCopyDoc(xml, 1)); /* 1 => recursive */ return Data_Wrap_Struct(klass, NULL, dealloc, ss); } diff --git a/test/helper.rb b/test/helper.rb index b34c7d47c6..8a5bd954a3 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -12,6 +12,8 @@ class TestCase < Test::Unit::TestCase ASSETS_DIR = File.join(File.dirname(__FILE__), 'files') XML_FILE = File.join(ASSETS_DIR, 'staff.xml') XSLT_FILE = File.join(ASSETS_DIR, 'staff.xslt') + EXSLT_FILE = File.join(ASSETS_DIR, 'exslt.xslt') + EXML_FILE = File.join(ASSETS_DIR, 'exslt.xml') HTML_FILE = File.join(ASSETS_DIR, 'tlm.html') unless RUBY_VERSION >= '1.9' diff --git a/test/test_xslt_transforms.rb b/test/test_xslt_transforms.rb index b927382865..5d14c01bb3 100644 --- a/test/test_xslt_transforms.rb +++ b/test/test_xslt_transforms.rb @@ -26,4 +26,19 @@ def test_transform assert result = style.apply_to(doc) assert_match %r{

}, result end + + def test_exslt + assert doc = Nokogiri::XML.parse(File.read(EXML_FILE)) + assert doc.xml? + + assert style = Nokogiri::XSLT.parse(File.read(EXSLT_FILE)) + result_doc = Nokogiri::XML.parse(style.apply_to(doc)) + + assert_equal 'func-result', result_doc.at('/root/function').content + assert_equal 3, result_doc.at('/root/max').content.to_i + assert_match( + /\d{4}-\d\d-\d\d-\d\d:\d\d/, + result_doc.at('/root/date').content + ) + end end