{"action":"created","issue":{"url":"https://api.github.com/repos/orbeon/orbeon-forms/issues/2127","labels_url":"https://api.github.com/repos/orbeon/orbeon-forms/issues/2127/labels{/name}","comments_url":"https://api.github.com/repos/orbeon/orbeon-forms/issues/2127/comments","events_url":"https://api.github.com/repos/orbeon/orbeon-forms/issues/2127/events","html_url":"https://github.com/orbeon/orbeon-forms/issues/2127","id":62150970,"number":2127,"title":"Web XForms: XPath 2 API","user":{"login":"ebruchez","id":105769,"avatar_url":"https://avatars.githubusercontent.com/u/105769?v=3","gravatar_id":"","url":"https://api.github.com/users/ebruchez","html_url":"https://github.com/ebruchez","followers_url":"https://api.github.com/users/ebruchez/followers","following_url":"https://api.github.com/users/ebruchez/following{/other_user}","gists_url":"https://api.github.com/users/ebruchez/gists{/gist_id}","starred_url":"https://api.github.com/users/ebruchez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ebruchez/subscriptions","organizations_url":"https://api.github.com/users/ebruchez/orgs","repos_url":"https://api.github.com/users/ebruchez/repos","events_url":"https://api.github.com/users/ebruchez/events{/privacy}","received_events_url":"https://api.github.com/users/ebruchez/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/orbeon/orbeon-forms/labels/Labs","name":"Labs","color":"009800"},{"url":"https://api.github.com/repos/orbeon/orbeon-forms/labels/RFE","name":"RFE","color":"444444"},{"url":"https://api.github.com/repos/orbeon/orbeon-forms/labels/XForms","name":"XForms","color":"ededed"}],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-03-16T17:15:35Z","updated_at":"2015-03-17T23:19:09Z","closed_at":null,"body":"This is a subproject of #1221.\r\n\r\nIn order to run XForms on the client, an XPath 2 implementation is needed. The obvious choice is to use the Saxon XPath processor:\r\n\r\n- it already compiles to JavaScript as part of Saxon-CE\r\n- it will maximize compatibility with our server code\r\n- it's pretty much the only reasonable implementation anyway\r\n\r\nIdeally, we would like Scala.js to be able to support compiling Java! But it's not the case at this time. So the suggested approach is to use a modified version of [Saxon-CE](http://www.saxonica.com/ce/user-doc/1.1/index.html).\r\n\r\nSaxon-CE is almost but not quite exactly what we need:\r\n\r\n- it does include the XPath 2 processor\r\n- it operates on the browser's W3C DOM trees\r\n- but it doesn't expose an API for it (see [2014-07-04 question](https://saxonica.plan.io/boards/1/topics/5977))\r\n- some features have been removed which we might need (see [](http://dev.saxonica.com/blog/mike/2013/09/reducing-the-size-of-saxon-ce.html))  \r\n      - \"all nodes in Saxon-CE are untyped, so this type will never match anything\"\r\n\r\nWe need an API, as there is absolutely no compatibility between GWT and Scala.js except via JavaScript.\r\n\r\nAPI requirements:\r\n\r\n- compile expression, passing static context\r\n- execute compiled expression, passing DOM node + pos, variable resolver\r\n  - Q: Which types do values have? NodeInfo? DOM nodes, what about atomic values? Plain JS values?\r\n  - Q: If we use NodeInfo, how do we share it between Scala.js and GWT? Or could we use 2 implementations of NodeInfo: one internally on the Saxon-CE side, one on the Scala.js side?\r\n- provide custom function library with access to caller context\r\n  - Q: How, if functions are implemented in Scala? need custom API for that?\r\n  - need to pass our XForms context\r\n- support DOM returning typed values such as `DecimalValue`\r\n\r\nNon-requirements:\r\n\r\n- XSLT support doesn't need to be exposed (and shouldn't be if that leads to a smaller footprint)\r\n\r\nSteps\r\n\r\n- [x] try to compile Saxon-CE locally\r\n- [ ] write first naive API: just compile and run and expression provided as a string\r\n- [ ] try out native API and see where that leads\r\n- [ ] define and write first API usable for first steps\r\n- [ ] figure out how to hook up our custom function library\r\n- [ ] update DOM wrappers to support typed values\r\n- [ ] figure out whether/how to re-add code for typed values which might be missing"},"comment":{"url":"https://api.github.com/repos/orbeon/orbeon-forms/issues/comments/82636398","html_url":"https://github.com/orbeon/orbeon-forms/issues/2127#issuecomment-82636398","issue_url":"https://api.github.com/repos/orbeon/orbeon-forms/issues/2127","id":82636398,"user":{"login":"ebruchez","id":105769,"avatar_url":"https://avatars.githubusercontent.com/u/105769?v=3","gravatar_id":"","url":"https://api.github.com/users/ebruchez","html_url":"https://github.com/ebruchez","followers_url":"https://api.github.com/users/ebruchez/followers","following_url":"https://api.github.com/users/ebruchez/following{/other_user}","gists_url":"https://api.github.com/users/ebruchez/gists{/gist_id}","starred_url":"https://api.github.com/users/ebruchez/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ebruchez/subscriptions","organizations_url":"https://api.github.com/users/ebruchez/orgs","repos_url":"https://api.github.com/users/ebruchez/repos","events_url":"https://api.github.com/users/ebruchez/events{/privacy}","received_events_url":"https://api.github.com/users/ebruchez/received_events","type":"User","site_admin":false},"created_at":"2015-03-17T23:19:09Z","updated_at":"2015-03-17T23:19:09Z","body":"Another option might be to convert Java files to Scala. IntelliJ or [scalagen](https://github.com/mysema/scalagen/tree/master/scalagen) can help.\r\n\r\nI tried running scalagen and it went through, except for `GenericLogHandler` (which I converted with IntelliJ). Of course things don't compile as there are lots of errors. Is it reasonable to go through 379 converted files to fix errors, maybe compare with the original Java source, and get this to compile?\r\n\r\n- drawbacks\r\n  - initial porting/compilation task\r\n  - difficulty of keeping port up to date with upstream Saxon work\r\n- benefits\r\n  - no impedance mismatch between this and the XForms processor's code\r\n    - calling from XForms\r\n    - function library\r\n    - DOM access\r\n  - possibly (but uncertain): more optimized JS output (Scala.js's cool DCE!)\r\n"}}