Skip to content

Commit

Permalink
Register EXSLT extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
albanm committed Jan 13, 2015
1 parent d777ff0 commit 5bc62ce
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 3 deletions.
2 changes: 2 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
8 changes: 6 additions & 2 deletions src/node_libxslt.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
#include <libxslt/xslt.h>
#include <libxslt/transform.h>
#include <libxslt/xsltutils.h>
#include <libexslt/exslt.h>

// includes from libxmljs
#include <xml_syntax_error.h>
Expand Down Expand Up @@ -72,7 +71,6 @@ class StylesheetWorker : public NanAsyncWorker {

NAN_METHOD(StylesheetAsync) {
NanScope();

libxmljs::XmlDocument* doc = node::ObjectWrap::Unwrap<libxmljs::XmlDocument>(args[0]->ToObject());
NanCallback *callback = new NanCallback(args[1].As<Function>());
NanAsyncQueueWorker(new StylesheetWorker(doc, callback));
Expand Down Expand Up @@ -196,12 +194,18 @@ NAN_METHOD(ApplyAsync) {
NanReturnUndefined();
}

NAN_METHOD(RegisterEXSLT) {
exsltRegisterAll();
NanReturnUndefined();
}

// Compose the module by assigning the methods previously prepared
void InitAll(Handle<Object> exports) {
Stylesheet::Init(exports);
exports->Set(NanNew<String>("stylesheetSync"), NanNew<FunctionTemplate>(StylesheetSync)->GetFunction());
exports->Set(NanNew<String>("stylesheetAsync"), NanNew<FunctionTemplate>(StylesheetAsync)->GetFunction());
exports->Set(NanNew<String>("applySync"), NanNew<FunctionTemplate>(ApplySync)->GetFunction());
exports->Set(NanNew<String>("applyAsync"), NanNew<FunctionTemplate>(ApplyAsync)->GetFunction());
exports->Set(NanNew<String>("registerEXSLT"), NanNew<FunctionTemplate>(RegisterEXSLT)->GetFunction());
}
NODE_MODULE(node_libxslt, InitAll);
3 changes: 2 additions & 1 deletion src/node_libxslt.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
NAN_METHOD(StylesheetSync);
NAN_METHOD(StylesheetASync);
NAN_METHOD(ApplySync);
NAN_METHOD(ApplyAsync);
NAN_METHOD(ApplyAsync);
NAN_METHOD(RegisterEXSLT);
13 changes: 13 additions & 0 deletions test/libxslt.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,4 +164,17 @@ describe('node-libxslt', function() {
result.should.match(/&lt;bar\/&gt;/);
});
});

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();
});
});
});
});
});
8 changes: 8 additions & 0 deletions test/resources/min-value.xsl
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:math="http://exslt.org/math">
<xsl:template match="values">
<result>
<xsl:text>Minimum: </xsl:text>
<xsl:value-of select="math:min(value)" />
</result>
</xsl:template>
</xsl:stylesheet>
6 changes: 6 additions & 0 deletions test/resources/values.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<values>
<value>7</value>
<value>11</value>
<value>8</value>
<value>4</value>
</values>

0 comments on commit 5bc62ce

Please sign in to comment.