- 1 function which transforms JSON to any text format
- Use the full power of AngularJS (templates, directives, filters, services, controllers)
- Extendable: easy to write your own plugins. Checkout the MS Word 2003 plugin which is currently used to test out these things
- Very testable! Just use the testtools you allready know to write your Javascript tests
"Who likes writing XSLT, please raise hands?"
"...and who likes maintaining XSLT?"
"...and who likes testing XSLT?"
At this moment, there probably aren't that many raised hands left.XSLT is very powerfull, but writing, maintaining and testing it is pretty hard.
...if we could transform data using the simplicity and power of AngularJS? Think about it:
- Nowadays most of our data is available in JSON, we loooove JSON
- Javascript is gaining more and more popularity, it runs both in client browsers as standalone using NodeJS.
- AngularJS offers enormous power, simplicity and testability
- Binding JSON to a template is very easy when using AngularJS
- Easy to extend by using your own directives, filter and controllers in templates
Why not trying to use all this stuff to transform JSON to... any text format?
Maybe we don't get the performance we can get using XSLT or the streaming capabilities, but I think for most use cases using AngularJS will be sufficient. And next to NodeJS and browsers, it shouldn't be that hard to make this useable in other environments like .Net or Java.
To avoid any confusion: this is not an AngularJS module. This library exposes a transform function, which internally bootstraps an AngularJS app. This app is used to perform the transformation.
Well this is a fairly simple example, but you get the idea.
var data = { company: "Some Company", employees: [ { name: 'Jack', age: '31'}, { name: 'Jill', age: '29'} ] };
<?xml version="1.0" encoding="UTF-8"?> <company> <name><at>{{company}}</at></name> <at ng-if="employees.length"> <employees> <at ng-repeat="employee in employees | orderBy:'age'"> <employee> <name age="{{age}}"><at>{{employee.name}}</at></name> </employee> </at> </employees> </at> </company>
var result = angularTransform({ data: data, template: template });
<?xml version="1.0" encoding="UTF-8"?> <company> <name>Some Company</name> <employees> <employee> <name age="29">Jill</name> </employee> <employee> <name age="31">Jack</name> </employee> </employees> </company>
npm install npm install -g bower bower install npm test
- AngularJS