Code Monkey home page Code Monkey logo

Comments (10)

gtamas avatar gtamas commented on June 10, 2024

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.

gtamas avatar gtamas commented on June 10, 2024

@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.

hbi99 avatar hbi99 commented on June 10, 2024

I’ll write as soon as I am at a computer 😊

from defiant.js.

gtamas avatar gtamas commented on June 10, 2024

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.

hbi99 avatar hbi99 commented on June 10, 2024

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.

gtamas avatar gtamas commented on June 10, 2024

ok thx! that sounds great! :) mine is a cli app, i need to make this work somehow

from defiant.js.

ChrisChinchilla avatar ChrisChinchilla commented on June 10, 2024

Trying something similar here :)

from defiant.js.

hbi99 avatar hbi99 commented on June 10, 2024

@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.

hbi99 avatar hbi99 commented on June 10, 2024

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:
image

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:

image

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.

gtamas avatar gtamas commented on June 10, 2024

@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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.