XJSLT is an XSLT 2.0 compiler (targeting JavaScript) written in TypeScript, depending on fontoxpath for an XPath implementation.
XJSLT works by compiling stylesheets to runnable JavaScript. These compiled stylesheets can be used immediately in the command line, or they can be save for later use in the command line. They can also be used programmatically either in the browser or in another JavaScript runtime.
Tested with node 20 and in Chrome and Firefox.
npm install && npm run build
xjslt jats-html.xsl <(curl -s https://jats.nlm.nih.gov/publishing/tag-library/1.1/FullArticleSamples/bmj_sample.xml)
XJSLT can compile XSLT stylesheets into executable JavaScript code, which can then be deployed to various platforms that support JavaScript, including the browser, NodeJS, and potentially other JavaScript runtimes. The following are some examples of how to do this for the browser, google cloud functions, and cloudflare edge functions. Note that this compiled .js
may need to be recompiled if the xjslt version changes.
xjslt compile --web jats-html.xsl examples/html/transform.js
- Open
examples/html/example.html
(will load the generatedtransform.js
file)
xjslt compile jats-html.xsl
xjslt transform.js <(curl -s https://jats.nlm.nih.gov/publishing/tag-library/1.1/FullArticleSamples/bmj_sample.xml)
xjslt compile --standalone jats-html.xsl examples/google-cloud/transform.js
cd examples/google-cloud
npm install
npx @google-cloud/functions-framework --target=transform
- Visit http://localhost:8080/?url=https://jats.nlm.nih.gov/publishing/tag-library/1.1/FullArticleSamples/bmj_sample.xml
xjslt compile --standalone jats-html.xsl examples/cloudflare/src/transform.js
cd examples/cloudflare
npm install
npm run start
- Visit http://localhost:8787/?url=https://jats.nlm.nih.gov/publishing/tag-library/1.1/FullArticleSamples/bmj_sample.xml
if
/choose/when/otherwise
- conditional evaluationtemplate
apply-templates
/for-each
- recursive evaluationelement
/attribute
/value-of
- dynamic elements, attributes, and text- literal text and xml element output
variable
- namespaces
sort
include
/import
result-document
- 2212 passing tests in the XSLT test suite (https://github.com/w3c/xslt30-test) (2424 not passing)
for-each-group
(onlygroup-by
supported)function
basically working, with better typing TBDoutput
not all options supported
-
attribute-set
-
number
-
analyze-string
(depends on bwrrp/xspattern.js#9) - tunneled parameters
- … (probably other things I’m not aware of or forgot)