diff --git a/index.js b/index.js index d16e7e3..3575641 100644 --- a/index.js +++ b/index.js @@ -7,6 +7,8 @@ var fs = require('fs'); var libxmljs = require('libxmljs'); var binding = require('bindings')('node-libxslt'); +binding.registerEXSLT(); + /** * A compiled stylesheet. Do not call this constructor, instead use parse or parseFile. * diff --git a/src/node_libxslt.cc b/src/node_libxslt.cc index 01e7f0b..77254fd 100644 --- a/src/node_libxslt.cc +++ b/src/node_libxslt.cc @@ -5,7 +5,6 @@ #include #include #include -#include // includes from libxmljs #include @@ -72,7 +71,6 @@ class StylesheetWorker : public NanAsyncWorker { NAN_METHOD(StylesheetAsync) { NanScope(); - libxmljs::XmlDocument* doc = node::ObjectWrap::Unwrap(args[0]->ToObject()); NanCallback *callback = new NanCallback(args[1].As()); NanAsyncQueueWorker(new StylesheetWorker(doc, callback)); @@ -196,6 +194,11 @@ NAN_METHOD(ApplyAsync) { NanReturnUndefined(); } +NAN_METHOD(RegisterEXSLT) { + exsltRegisterAll(); + NanReturnUndefined(); +} + // Compose the module by assigning the methods previously prepared void InitAll(Handle exports) { Stylesheet::Init(exports); @@ -203,5 +206,6 @@ void InitAll(Handle exports) { exports->Set(NanNew("stylesheetAsync"), NanNew(StylesheetAsync)->GetFunction()); exports->Set(NanNew("applySync"), NanNew(ApplySync)->GetFunction()); exports->Set(NanNew("applyAsync"), NanNew(ApplyAsync)->GetFunction()); + exports->Set(NanNew("registerEXSLT"), NanNew(RegisterEXSLT)->GetFunction()); } NODE_MODULE(node_libxslt, InitAll); \ No newline at end of file diff --git a/src/node_libxslt.h b/src/node_libxslt.h index 6980e78..fd7df1a 100644 --- a/src/node_libxslt.h +++ b/src/node_libxslt.h @@ -4,4 +4,5 @@ NAN_METHOD(StylesheetSync); NAN_METHOD(StylesheetASync); NAN_METHOD(ApplySync); -NAN_METHOD(ApplyAsync); \ No newline at end of file +NAN_METHOD(ApplyAsync); +NAN_METHOD(RegisterEXSLT); \ No newline at end of file diff --git a/test/libxslt.js b/test/libxslt.js index edcb668..e63472a 100644 --- a/test/libxslt.js +++ b/test/libxslt.js @@ -164,4 +164,17 @@ describe('node-libxslt', function() { result.should.match(/<bar\/>/); }); }); + + describe('libexslt bindings', function(){ + it('should expose EXSLT functions', function(callback){ + libxslt.parseFile('test/resources/min-value.xsl', function(err, stylesheet){ + should.not.exist(err); + stylesheet.applyToFile('test/resources/values.xml', function(err, result){ + should.not.exist(err); + result.should.match(/Minimum: 4/); + callback(); + }); + }); + }); + }); }); \ No newline at end of file diff --git a/test/resources/min-value.xsl b/test/resources/min-value.xsl new file mode 100644 index 0000000..e3eb925 --- /dev/null +++ b/test/resources/min-value.xsl @@ -0,0 +1,8 @@ + + + + Minimum: + + + + \ No newline at end of file diff --git a/test/resources/values.xml b/test/resources/values.xml new file mode 100644 index 0000000..349a8ad --- /dev/null +++ b/test/resources/values.xml @@ -0,0 +1,6 @@ + + 7 + 11 + 8 + 4 + \ No newline at end of file