Closed mig82 closed 5 years ago
I'm afraid 9798f31 doesn't really address the issue. Notice I'm talking about using this in Node.js. I believe for this to work, you'd have to explicitly add exports.xpathParse = xpathParse
to your dist/xslt-processor.js
file. Is this a modification you'd be willing to do? I'd very much appreciate it and I'm sure other Node users would as well :)
@mig82 Have you tried it? xpathParse is now as exposed as the other properties. dist/xslt-processor.js
is merely the processed output file of what you can see here.
Inspecting the out put dist/xslt-processor.js
file it does indead end with
...;exports.xpathParse=xpathParse;
So I'm guessing you reported here without actually trying it out?
Actually, I did have a look. And what it exports is xmlParse
, not xpathParse
.
$ tail node_modules/xslt-processor/dist/xslt-processor.js
}
}
node = node.parentNode;
}
}
return ret;
}
exports.xsltProcess = xsltProcess;
exports.xmlParse = xmlParse;
Sorry. Still using the older version. My bad.
Ok, now xpathParse
is exposed. The problem I find now is that I can't seem to find the proper way to use it. I've tried this:
var xml = `<root xmlns:foo="http://www.foo.org/" xmlns:bar="http://www.bar.org">
<actors>
<actor id="1">Christian Bale</actor>
<actor id="2">Liam Neeson</actor>
<actor id="3">Michael Caine</actor>
</actors>
<foo:singers>
<foo:singer id="4">Tom Waits</foo:singer>
<foo:singer id="5">B.B. King</foo:singer>
<foo:singer id="6">Ray Charles</foo:singer>
</foo:singers>
</root>`;
var actor = xpathParse("//actor[1]/text()").evaluate(xml);
But I'm getting this error:
n.clone is not a function
So looking at your test suite I tried this instead -same declaration of the xml
variable:
const ExprContext = require('xslt-processor').ExprContext;
...
var actor = xpathParse("//actor[1]/text()").evaluate(
new ExprContext(xmlParse(xml))
);
But I'm afraid ExprContext
is not exposed by the module to be imported like this.
It would be great if you could add a small snippet to README.md to describe how to use xpathParse
.
It would be great if you could add a small snippet to README.md to describe how to use xpathParse.
It's probably better if you figure out exactly all the things you want/need exposed, create a ticket and I'll expose them for you then. Even better if you could create a PR with all the things you want changed. @mig82
Point taken. I'll do that.
Can't figure out how to use this to parse an XPath expression in Node.js. If I just do this:
This is all that comes out:
Just an object with two functions of which none is the
xpathParse
function tested here. Can you please shed some light on how to do this? The description of the package states:So I'm assuming it's possible.