Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,22 @@ const xml = slimdom.serializeToWellFormedString(resultDocument);
console.log(xml);
```

# Dynamic (not precompiled) use

xjslt can be used dynamically as well - that is, not precompiled. While precompiling the stylesheet is faster, this may be helpful in some circumstances.

## In the 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.
Expand Down
38 changes: 38 additions & 0 deletions examples/html/dynamic.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="stylesheet" content="https://raw.githubusercontent.com/egh/xjslt/refs/heads/main/jats-html.xsl"/>
<meta name="input" content="https://jats.nlm.nih.gov/publishing/tag-library/1.1/FullArticleSamples/bmj_sample.xml"/>
<script src="xjslt-web.js"></script>
<script>
async function fetchAndParse(url) {
let response = await fetch(url);
if (!response.ok) {
throw new Error(`Response status: ${response.status}`);
}
return new DOMParser().parseFromString(
await response.text(),
"application/xml",
);
}
async function update() {
const xsltUrl = document.querySelector('meta[name="stylesheet"]').content;
const inputUrl = document.querySelector('meta[name="input"]').content;
console.log("compiling");
const transform = xjslt.compile(await fetchAndParse(xsltUrl), new URL(xsltUrl));
console.log("compiled");
const input = await fetchAndParse(inputUrl);
console.log("fetching input");
transform(input, {
outputDocument: document,
outputNode: document.querySelector("body"),
});
console.log("done");
}
update();
</script>
</head>
<body>
</body>
</html>
15 changes: 12 additions & 3 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
export default {
coveragePathIgnorePatterns: ["src/preprocess"],
preset: "ts-jest",
testEnvironment: "node",
reporters: [["jest-simple-dot-reporter", { color: true }]],
testPathIgnorePatterns: ["examples"],
projects: [
{
displayName: "node",
preset: "ts-jest",
testEnvironment: "node",
},
{
displayName: "jsdom",
preset: "ts-jest",
testEnvironment: "jsdom",
},
],
};
Loading