Skip to content

Commit

Permalink
add exslt support
Browse files Browse the repository at this point in the history
  • Loading branch information
Rick Frankel authored and flavorjones committed Dec 17, 2008
1 parent db4ab12 commit 00ce67a
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -14,4 +14,5 @@ mkmf.log
cross
tags
stash
.rake_tasks

16 changes: 15 additions & 1 deletion ext/nokogiri/extconf.rb
Expand Up @@ -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


Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions ext/nokogiri/xslt_stylesheet.c
Expand Up @@ -3,6 +3,7 @@
#include <libxslt/xsltInternals.h>
#include <libxslt/xsltutils.h>
#include <libxslt/transform.h>
#include <libexslt/exslt.h>

static void dealloc(xsltStylesheetPtr doc)
{
Expand All @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions test/helper.rb
Expand Up @@ -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'
Expand Down
15 changes: 15 additions & 0 deletions test/test_xslt_transforms.rb
Expand Up @@ -26,4 +26,19 @@ def test_transform
assert result = style.apply_to(doc)
assert_match %r{<h1></h1>}, 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

0 comments on commit 00ce67a

Please sign in to comment.