GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - egh/xjslt: An XSLT 2.0 transpiler (targeting JavaScript) written in TypeScript.

BranchesTags
Open more actions menu

Latest commit

 

History

436 Commits
436 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
.vscode
.vscode
 
 
examples
examples
 
 
src
src
 
 
test
test
 
 
.gitignore
.gitignore
 
 
.nvmrc
.nvmrc
 
 
COPYING
COPYING
 
 
COPYING.LESSER
COPYING.LESSER
 
 
README.md
README.md
 
 
jats-html.xsl
jats-html.xsl
 
 
jest.config.ts
jest.config.ts
 
 
package-lock.json
package-lock.json
 
 
package.json
package.json
 
 
tsconfig.json
tsconfig.json
 
 
webpack.config.ts
webpack.config.ts
 
 

Repository files navigation

XJSLT - An XSLT to JavaScript transpiler

XJSLT is a substantially complete and performant XSLT 2.0 to JavaScript transpiler. XJSLT implements most features of XSLT 2 (see below for a few exceptions) and passes much of the test suite. XJSLT is written in TypeScript and depends 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.

XJSLT runs in javascript runtimes and on the browser. It has been tested with node and in Chrome and Firefox.

Getting started

Installation:

npm install -g xjslt

Or use

npx xjslt …

or from source:

git clone https://github.com/egh/xjslt.git && cd xjslt

Command line invocation:

npm exec -- xjslt run examples/jats-html.xsl examples/bmj_sample.xml

Compilation examples

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.

In the browser

For the following commands you will want to have the source checked out.

npm exec -- xjslt compile --web examples/jats-html.xsl examples/html/transform.js
  • Open examples/html/example.html (will load the generated transform.js file)

For reuse in the command line

Pre-compiling a .js file will speed up transformation.

npm exec -- xjslt compile examples/jats-html.xsl
npm exec -- xjslt run transform.js examples/bmj_sample.xml

Examples of use in cloud functions

XJSLT can be used to compile XSLT into JavaScript that can be used in, for example, cloud functions. Here are two examples of how it could be used in cloud functions to dynamically transform XML data into HTML.

In a google cloud function

npm exec -- xjslt compile --standalone examples/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

In a cloudflare edge function

npm exec -- xjslt compile --standalone examples/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

Programmatic API (Node.js)

Use compile from xjslt/compile to build a transform function directly in Node.js without writing any files to disk. The stylesheet is passed as a parsed document, and the returned function can be called immediately.

import * as slimdom from "slimdom";
import { readFileSync } from "fs";
import { compile } from "xjslt/compile";

const stylesheetPath = "jats-html.xsl";
const xslt = slimdom.parseXmlDocument(readFileSync(stylesheetPath, "utf-8"));
const transform = compile(xslt);

// Transform an XML document
const input = slimdom.parseXmlDocument(readFileSync("article.xml", "utf-8"));
const results = transform(input);
const resultDocument = results.get("#default");

const xml = slimdom.serializeToWellFormedString(resultDocument);

console.log(xml);

Programmatic API (browser)

npm exec webpack && cp dist/xjslt-web.js examples/html/

Open examples/html/dynamic.html in your browser.

In node

(To be documented.)

Supported features

All core features of XSLT 2.0. Roughly 50% of tests in the XSLT test suite (https://github.com/w3c/xslt30-test) pass - but many of these tests are for edge cases.

Incompletely supported features

  • function basically working, with better typing TBD
  • output not all options supported
  • number basic support, not all options supported

TODO (not yet implemented)

  • analyze-string (depends on bwrrp/xspattern.js#9)
  • tunneled parameters

Running tests

The test suite includes both unit tests and a subset of the W3C XSLT 3.0 test suite. To run tests, ensure dependencies are installed:

npm install

and then run tests:

npm test

Contributing

Some functionality, including import and include, is implemented in terms of preprocessors: xslt stylesheets that are applied to the xslt stylesheet itself before it is compiled. If you make changes that impact these preprocessors, you will need to run npm run build-preprocessors to recompile them.

About

An XSLT 2.0 transpiler (targeting JavaScript) written in TypeScript.

Topics

javascriptxslt

Resources

Readme
Activity

Stars

34 stars

Watchers

1 watching

Forks

5 forks
Report repository

Releases

Packages

Used by

Contributors

Languages

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.