Closed wendellpiez closed 1 year ago
Wendell,
Currently the jwiXML JavaScript library must be loaded via a script reference on the top-level (X)HTML web page. There is no mechanism (and probably will never be) to get it compiled into the SaxonJS runtime. The dist/jwiXML.processor.xsl
file (in the ZIP) adds a few XSLT functions that connect to that library - have a look at it.
To load a fixed grammar, all you should need to do is something like the attached file (XSLT renamed as txt to allow attachment), which is a very minor variation of the sample application. Basically:
xs:string
variable.jwL:compileGrammar($grammar)
. This will be evaluated once and may be reused many times.jwL:parse($compiled-grammar,$input)
to do the parse - the 'tree' member of the map is the XML version of the parse, or error if that is the case.jwiXML.processor.xsl
) to connect from the XSLT to the separately loadedjwiXML.adv.cls.js
JavaScript libraryHope that helps.
It does indeed help, quite a bit. This is interesting and I will try it out. Indeed if the function result is cached I'm not sure it would make a meaningful difference in performance to serve up some pre-digested or compiled form. Whether it would make any other meaningful difference (application security?) I will have to ponder.
Thanks!
Actually in its way it's pretty secure, if all I serve is the libraries plus my SEF. Hm!
This may become evident as I look more closely but so far I see no simple guidance. A pointer would be gratefully received, or tips, or a tdb.
I have a grammar all written: how do I hardwire it into a SaxonJS application?
Presumably I do not need to export the compiler XSLT and have the parser generated fresh at runtime. Can I instead compile my grammar 'all the way' in a build (i.e. when I export my SEF), and have it delivered as a fully-functional library parsing my format, whether as/in/with XSLT/SEF, a Javascript function library (Grammar object definition?) or otherwise?
Thoughts? I am very much liking what I am seeing so far.