-
Notifications
You must be signed in to change notification settings - Fork 68
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support extension functions written in JavaScript #2
Comments
Nice ! I will have a look, but I don't have much time for this so I can't make any promise. Of course a pull request is welcome. |
Sorry, but things are not looking very good on this topic. I have done a few tests saved in this commit: 29f1ad6 But I am not convinced that it will bring a satisfactory solution. |
please! i think this is the last obstacle on my port... |
EXSLT is a fixed set of extension functions, and I believe that libxslt supports most of these already. What I'm talking about here is the option to add arbitrary extension functions written in JS.
Funny, you started at a completely different point than where I'd have started. The fact that there are a large number of drive-by fixes in that commit makes reading it difficult, though. My first steps were trying to get type conversions implemented. Which is easy enough for simple types, but gets really complicated if you are dealing with nodes. For that one would need to wrap large parts of the libXML API for use from node. As I recall, node-libxslt ships its own version of libXML so it would have to do that as well to provide consistency. Perhaps it would be better to build on some existing libXML wrapper for Node instead? Linking against that might be tricky, but that approach would ensure consistent versions. But I guess that even if we don't get all types supported yet, this would still be useful for several applications. Having some part of the functionality is better than none at all, imo.
You don't. The return type of any extension function has to be converted to an XPath data type. So anything which is not boolean, numeric, node or node list (no guarantee that this list is exhaustive) should probably be turned into a string via a simple I know XSLT in Java allows passing arbitrary Java objects between extension functions. It might be possible to do the same here as well. But if at all I'd consider this for a later improvement, not for the initial implementation of extension functions.
Async processing is something I hadn't considered at all. I guess the only clean way would be to run the XSLT processor in a separate thread, and to block that thread while the main node thread processes some callback. Once that yields a result, the result could be returned to XSLT. Something like this JS-like pseudocode, but actually written in C:
If the callback throws an exception, that might make things even more difficult. In an ideal world, any exception raised by the callback would cause the XSLT process to abort and would get passed to the error event handler of the XSLT event dispatcher. I'm not sure whether libxslt is properly reentrant. If not, then we'd have to make sure that we don't start more than one XSLT process at the same time. But that's a general issue, not specific to extension functions, right? |
ok, built in module functions are working (at least I've tested with evaluate, Ok). |
Here is my current work in progress. It's already usable to some degree: I can pass values of type boolean, number and string in both directions, and I can call the custom function in synchroneous and in asynchroneous context. Supporting other types, nodes and node sets in particular, will probably require more work since these need to be properly wrapped. But as a starting point I'm quite happy with this here. |
Hello.I'm trying to use regular expressions in my xslt.Is there any way to achieve this?Thanks! |
@tasoss: node-libxslt supports exslt, which supports regular expressions. Should not be a problem, but it's qzite distinct from what this issue here is about. |
Thanks for answering...Sorry for posting here.I will try to post on a forum/mailing list or something because i need more help on reg. expressions.Thanks again! |
It would be nice if we could extend the XSLT resp. XPath language using Extensions functions. LibXSLT provides custom extensions. It would be great to have that API wrapped on the JavaScript side, so one can write extension functions there.
The text was updated successfully, but these errors were encountered: