Comments (10)
Update.
After checking the code, I tried this with node 10.8:
const def = require('defiant.js');
def.init()
.then(() => {
return def.register_template(
'books',
'<script type="<defiant/xsl-template"><xsl:template name="books"><xsl:for-each select="//movie"><xsl:value-of select="title"/><br/></xsl:for-each></xsl:template></script>'
);
})
.then(() => {
return def.render('books', { movie: [{ title: 'thing' }] });
})
.then(res => {
console.log(res);
})
.catch(e => {
throw new Error(e);
});
But I'm getting this error:
Unhandled promise rejection (rejection id: 1): Error: Error: Evaluation failed: TypeError: Cannot read property 'setAttribute' of null
at Object.render (:6:1323)
What am I doing wrong? This seems to be a bug.
from defiant.js.
@hbi99
Please get back to me on this if you can. It would be so awesome to use this lib in my app. :) Searching is good, snapshot is good, so we only have to figure out rendering now.
from defiant.js.
I’ll write as soon as I am at a computer 😊
from defiant.js.
OK thx vety much
By the way, this is when the error happens. Line 62 of defiant.js:
temp = this.node.selectSingleNode(this.xsl_template, tmpltXpath);
This returns null, but null is not handled in the next line..
from defiant.js.
I know why it happens. So i will post you the code to get it running. Also, there is a middleware i’ve written for express.js and koa - that is doing exactly what you want and the setup is easy complemented with debug tool. I’ll write more with example code 😊
from defiant.js.
ok thx! that sounds great! :) mine is a cli app, i need to make this work somehow
from defiant.js.
Trying something similar here :)
from defiant.js.
@gtamas,
First of all, sorry for delayed response. I am in Spain right now and we had a tiresome travel yesterday and I was exhausted in the night. Anyway, regarding your script - when I switched this library from Grunt Gulp - which was a few weeks ago, I messed up with the position of a IE-polyfill code, which in turn messed up the rendering functionality of Defiant. This is fixed and a new version is deployed 2.1.3
. But also, you need to adjust your script to this - the only change is the register_template method:
const def = require('defiant.js');
def.init()
.then(() => {
return def.register_template(
'<xsl:template name="books"><xsl:for-each select="//movie"><xsl:value-of select="title"/><br/></xsl:for-each></xsl:template>'
);
})
.then(() => {
return def.render('books', { movie: [{ title: 'thing' }] });
})
.then(res => {
console.log(res);
})
.catch(e => {
throw new Error(e);
});
from defiant.js.
Now regarding the documentation; it is coming with some really cool features - please be patient, because the new feature will is a library that allows features like Jupyter Notebook but in markdown-files. I'll get back to you soon :-)
Regarding the middleware for express.js
- you can try it out if you follow the instructions below. If not, here are two screenshots with explanation of the debug-feature - though it is not as advanced as I want it to be.
If you've followed the instructions below, you should see something like this:
But, you can in dev-mode add ?debug=true
. When you do this, you will see the debug view which in turn will display your XSL file to the left, your JSON data to the right. But the neat feature is that you can move the cursor in the XSL file and the XPaths, and the tools can and will indicate what the selections match. Similar to this view:
If you want to try it out, here are the instructions, to enter in bash / terminal:
$ mkdir tmp
$ cd tmp
$ npm init // press yes all the way
$ npm install rebellious --save
$ cd node_modules/rebellious
$ npm install
$ cd example/
$ nodemon app.js // in your browser, go to http://localhost:3000/books
from defiant.js.
@hbi99
Thank you very much! The code works fine :) cool.
Regarding the middleware and the example, I installed them. This is pretty cool, especially the debug feature!
So using this middleware I can use XSL templates and run them in visual debug mode. That's nice! :) Will this debug feature also be able to execute XPATH queries? I mean, there is a bar at the bottom which seems to be designed for queries, but it's read-only in my browser.
Anyway thanks again for all the help. Now I will implement the features I planned. :)
Btw, when can we expect the Jupyter Notebook-like stuff? Sounds interesting as well.
from defiant.js.
Related Issues (20)
- Cannot install via Yarn HOT 8
- Support all UTF8 character set ! HOT 2
- does not work in IE11 HOT 9
- NodeJS: registering multiple templates is not possible HOT 1
- Question: XSLT, XPath versions HOT 1
- NodeJS XML <-> JSON HOT 3
- Not able to find values with & HOT 2
- Chrome 70 breaks JSON.search HOT 2
- Multiple callback calls on async getSnapshot HOT 4
- Does not pass "use strict" HOT 1
- Split packet so npm users don't need to install pupeteer on pure browser installation HOT 8
- Defiantjs.com Certificate HOT 1
- TypeError: Cannot read property 'search' of undefined HOT 1
- TypeError: null is not an object (evaluating 'constr.toString().match(self.rx_function)') HOT 2
- Handle keys with numbers HOT 1
- Nodejs: Session closed when running defiant.search a second time HOT 1
- Currently unable to pass args to puppeteer launch method. HOT 1
- no search result, if first letter capital Ä (umlaut) HOT 1
- find parent using recursion HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from defiant.js.