shepmaster / sxd-xpath

An XPath library in Rust
Apache License 2.0
119 stars 34 forks source link

Implement EXSLT functions, e.g. exsl:node-set ? #109

Closed Boddlnagg closed 7 years ago

Boddlnagg commented 7 years ago

I have an XSLT script that uses the node-set function defined by EXSLT. It works in Firefox, which has some EXSLT support. Depending on how hard this would be to implement (node-set shouldn't be too hard), I think having it in this Rust library would be great!

Boddlnagg commented 7 years ago

Oh, I see there already is #50 ... sorry. You can consider this to be a special request for the node-set function, then.

shepmaster commented 7 years ago

Thank you! I'm going to go ahead and close this as a duplicate of #50. I definitely agree that there's a bunch of EXSLT functionality that is super useful.

(node-set shouldn't be too hard)

Implementing functions isn't that bad! You can take a look at the file that defines all the current functions. The documentation for Context even shows how you can create user-specified functions.

I'd certainly appreciate a pull request adding node-set!

Boddlnagg commented 7 years ago

I see that implementing node-set doesn't make sense right now, because there is no implementation of XSLT yet. The whole point of node-set is to turn "Result Tree Fragments" into proper XPath Nodesets, but right now "Result Tree Fragments" do not exist, because they are an addition of XSLT 1.0 to XPath (see https://www.w3.org/TR/xslt#section-Result-Tree-Fragments). I actually remember now that I opened #61 about this almost two years ago 😅 .

Another complication is that EXSLT functions are namespaced (e.g. xmlns:exsl="http://exslt.org/common", then you can use exsl:node-set(...)), which currently does not seem to be supported and actually also only makes sense in the context of XSLT.

shepmaster commented 7 years ago

which currently does not seem to be supported

It should be:

context.set_function(("http://exslt.org/common", "node-set"), NodeSetFunction)

only makes sense in the context of XSLT

Nah, that's a concept of XPath.