diff --git a/README.md b/README.md index 3d9e40a..4634754 100644 --- a/README.md +++ b/README.md @@ -18,7 +18,7 @@ Basic usage ```js var lixslt = require('libxslt'); -var stylesheet = libxslt.stylesheet(stylesheetString); +var stylesheet = libxslt.parse(stylesheetString); var params = { MyParam: 'my value' @@ -47,7 +47,7 @@ var lixslt = require('libxslt'); var libxmljs = require('libxmljs'); var stylesheetObj = libxmljs.parseXml(stylesheetString); -var stylesheet = libxslt.stylesheet(stylesheetObj); +var stylesheet = libxslt.parse(stylesheetObj); var document = libxmljs.parseXml(documentString); stylesheet.apply(document, function(err, result){ @@ -69,7 +69,7 @@ In this case if a parsing error occurs it will be thrown. ```js var lixslt = require('libxslt'); -var stylesheet = libxslt.stylesheet(stylesheetString); +var stylesheet = libxslt.parse(stylesheetString); var result = stylesheet.apply(documentString); diff --git a/benchmark.js b/benchmark.js index c9b03ad..5b96d7b 100644 --- a/benchmark.js +++ b/benchmark.js @@ -5,7 +5,7 @@ var libxslt = require('./index'); var stylesheetStr = fs.readFileSync('./test/resources/cd.xsl', 'utf8'); var stylesheetObj = libxmljs.parseXml(stylesheetStr); -var stylesheet = libxslt.stylesheet(stylesheetObj); +var stylesheet = libxslt.parse(stylesheetObj); var docStr = fs.readFileSync('./test/resources/cd.xml', 'utf8'); var docObj = libxmljs.parseXml(docStr); @@ -22,14 +22,14 @@ var bench = function(name, iterations, f) { var stylesheetParsingStr = function(iterations, callback) { for (var i = 0; i < iterations; i++) { - libxslt.stylesheet(stylesheetStr); + libxslt.parse(stylesheetStr); } callback(); }; var stylesheetParsingObj = function(iterations, callback) { for (var i = 0; i < iterations; i++) { - libxslt.stylesheet(stylesheetObj); + libxslt.parse(stylesheetObj); } callback(); }; diff --git a/example.js b/example.js index c6c3f7e..cecc3de 100644 --- a/example.js +++ b/example.js @@ -6,7 +6,7 @@ var libxslt = require('./index'); var stylesheetSource = fs.readFileSync('./test/resources/cd.xsl', 'utf8'); var docSource = fs.readFileSync('./test/resources/cd.xml', 'utf8'); -var stylesheet = libxslt.stylesheet(stylesheetSource); +var stylesheet = libxslt.parse(stylesheetSource); //var result = stylesheet.apply(docSource); //console.log(result); diff --git a/index.js b/index.js index 85749b8..3273892 100644 --- a/index.js +++ b/index.js @@ -55,7 +55,7 @@ Stylesheet.prototype.apply = function(source, params, callback) { } }; -exports.stylesheet = function(source, callback) { +exports.parse = function(source, callback) { // stylesheet can be given as a string or a pre-parsed xml document if (typeof source === 'string') source = libxmljs.parseXml(source); @@ -64,56 +64,4 @@ exports.stylesheet = function(source, callback) { } else { return new Stylesheet(source, binding.stylesheetSync(source)); } -}; - -/* -var apply = function(stylesheet, source, params, callback) { - // xml can be given as a string or a pre-parsed xml document - var outputString = false; - if (typeof source === 'string') { - source = libxmljs.parseXml(source); - outputString = true; - } - // params are optional - if (typeof params === 'function') { - callback = params; - params = {}; - } - params = params || {}; - - // flatten the params object in an array - var paramsArray = []; - for(var key in params) { - paramsArray.push(key); - paramsArray.push(params[key]); - } - - // for some obscure reason I didn't manage to create a new libxmljs document in applySync, - // but passing a document by reference and modifying its content works fine - var result = new libxmljs.Document(); - - if (callback) { - binding.applyAsync(stylesheet, source, paramsArray, result, function(err){ - if (err) return callback(err); - callback(null, outputString ? result.toString() : result); - }); - } else { - binding.applySync(stylesheet, source, paramsArray, result); - return outputString ? result.toString() : result; - } -}; - -exports.stylesheet = function(stylesheetSource) { - // stylesheet can be given as a string or a pre-parsed xml document - if (typeof stylesheetSource === 'string') stylesheetSource = libxmljs.parseXml(stylesheetSource); - - var stylesheet = binding.stylesheetSync(stylesheetSource); - - stylesheetSource.stylesheet = stylesheet; - stylesheetSource.apply = function(source, params, callback){ - return apply(stylesheet, source, params, callback); - }; - - return stylesheetSource; -}; -*/ \ No newline at end of file +}; \ No newline at end of file diff --git a/test/libxslt.js b/test/libxslt.js index 771a51c..8980dbd 100644 --- a/test/libxslt.js +++ b/test/libxslt.js @@ -25,16 +25,16 @@ describe('node-libxslt bindings', function() { describe('stylesheet function', function() { it('should parse a stylesheet from a libxmljs xml document', function() { var stylesheetDoc = libxmljs.parseXml(stylesheetSource); - stylesheet = libxslt.stylesheet(stylesheetDoc); + stylesheet = libxslt.parse(stylesheetDoc); stylesheet.should.be.type('object'); }); it('should parse a stylesheet from a xml string', function() { - stylesheet = libxslt.stylesheet(stylesheetSource); + stylesheet = libxslt.parse(stylesheetSource); stylesheet.should.be.type('object'); }); it('should throw an error when parsing invalid stylesheet', function() { (function() { - libxslt.stylesheet('this is not a stylesheet!'); + libxslt.parse('this is not a stylesheet!'); }).should.throw(); }); });