{"id":13760876,"url":"https://github.com/DesignLiquido/xslt-processor","last_synced_at":"2025-05-10T11:32:09.667Z","repository":{"id":30785623,"uuid":"125993805","full_name":"DesignLiquido/xslt-processor","owner":"DesignLiquido","description":"A JavaScript XSLT processor without native library dependencies","archived":false,"fork":false,"pushed_at":"2024-04-13T23:44:27.000Z","size":1128,"stargazers_count":89,"open_issues_count":4,"forks_count":29,"subscribers_count":9,"default_branch":"main","last_synced_at":"2024-05-01T10:59:40.254Z","etag":null,"topics":["hacktoberfest","xml","xml-parser","xslt","xslt-files","xslt-stylesheet","xslt-templates","xsltproc"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"lgpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/DesignLiquido.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-03-20T09:35:37.000Z","updated_at":"2024-05-07T18:32:25.379Z","dependencies_parsed_at":"2023-11-24T14:28:19.683Z","dependency_job_id":"bb8497b7-6901-4b30-a731-931e3f67eb1d","html_url":"https://github.com/DesignLiquido/xslt-processor","commit_stats":null,"previous_names":["designliquido/xslt-processor","fiduswriter/xslt-processor"],"tags_count":48,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DesignLiquido%2Fxslt-processor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DesignLiquido%2Fxslt-processor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DesignLiquido%2Fxslt-processor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DesignLiquido%2Fxslt-processor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DesignLiquido","download_url":"https://codeload.github.com/DesignLiquido/xslt-processor/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":224684655,"owners_count":17352585,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest","xml","xml-parser","xslt","xslt-files","xslt-stylesheet","xslt-templates","xsltproc"],"created_at":"2024-08-03T13:01:25.260Z","updated_at":"2024-11-16T18:31:44.450Z","avatar_url":"https://github.com/DesignLiquido.png","language":"TypeScript","funding_links":[],"categories":["JavaScript","TypeScript"],"sub_categories":[],"readme":"# XSLT-processor\n\n_A JavaScript XSLT processor without native library dependencies._\n\n  \u003cp align=\"center\"\u003e\n    \u003ca href=\"https://github.com/DesignLiquido/xslt-processor/issues\" target=\"_blank\"\u003e\n      \u003cimg src=\"https://img.shields.io/github/issues/Designliquido/xslt-processor\" /\u003e\n    \u003c/a\u003e\n    \u003cimg src=\"https://img.shields.io/github/stars/Designliquido/xslt-processor\" /\u003e\n    \u003cimg src=\"https://img.shields.io/github/forks/Designliquido/xslt-processor\" /\u003e\n    \u003ca href=\"https://www.npmjs.com/package/xslt-processor\" target=\"_blank\"\u003e\n      \u003cimg src=\"https://img.shields.io/npm/v/xslt-processor\" /\u003e\n    \u003c/a\u003e\n    \u003cimg src=\"https://img.shields.io/npm/dw/xslt-processor\" /\u003e\n    \u003cimg src=\"https://img.shields.io/github/license/DesignLiquido/xslt-processor\" /\u003e\n  \u003c/p\u003e\n\n## How to\n\nInstall xslt-processor using [npm](https://docs.npmjs.com/about-npm) or [yarn](https://yarnpkg.com):\n\n```sh\nnpm install xslt-processor\n```\n\n```sh\nyarn add xslt-processor\n```\n\nWithin your ES2015+ code, import the `Xslt` class, the `XmlParser` class and use this way:\n\n```js\nimport { Xslt, XmlParser } from 'xslt-processor'\n\n// xmlString: string of xml file contents\n// xsltString: string of xslt file contents\n// outXmlString: output xml string.\nconst xslt = new Xslt();\nconst xmlParser = new XmlParser();\n// Either\nconst outXmlString = await xslt.xsltProcess(\n\txmlParser.xmlParse(xmlString),\n\txmlParser.xmlParse(xsltString)\n);\n// Or\nxslt.xsltProcess(\n\txmlParser.xmlParse(xmlString),\n\txmlParser.xmlParse(xsltString)\n).then(output =\u003e {\n  // `output` is equivalent to `outXmlString` (a string with XML).\n});\n```\n\nTo access the XPath parser, you can use the instance present at `Xslt` class:\n\n```js\nconst xslt = new Xslt();\nconst xPath = xslt.xPath;\n```\n\nOr ou can import it like this:\n\n```js\nimport { XPath } from 'xslt-processor'\n\nconst xPath = new XPath();\n```\n\nIf you write pre-2015 JS code, make adjustments as needed.\n\n### `Xslt` class options\n\nYou can pass an `options` object to `Xslt` class:\n\n```js\nconst options = {\n  escape: false,\n  selfClosingTags: true,\n  parameters: [{ name: 'myparam', value: '123' }],\n  outputMethod: 'xml'\n};\nconst xslt = new Xslt(options);\n```\n\n- `cData` (`boolean`, default `true`): resolves CDATA elements in the output. Content under CDATA is resolved as text. This overrides `escape` for CDATA content.\n- `escape` (`boolean`, default `true`): replaces symbols like `\u003c`, `\u003e`, `\u0026` and `\"` by the corresponding [HTML/XML entities](https://www.tutorialspoint.com/xml/xml_character_entities.htm). Can be overridden by `disable-output-escaping`, that also does the opposite, unescaping `\u0026gt;` and `\u0026lt;` by `\u003c` and `\u003e`, respectively.\n- `selfClosingTags` (`boolean`, default `true`): Self-closes tags that don't have inner elements, if `true`. For instance, `\u003ctest\u003e\u003c/test\u003e` becomes `\u003ctest /\u003e`.\n- `outputMethod` (`string`, default `xml`): Specifies the default output method. if `\u003cxsl:output\u003e` is declared in your XSLT file, this will be overridden.\n- `parameters` (`array`, default `[]`): external parameters that you want to use.\n    - `name`: the parameter name;\n    - `namespaceUri` (optional): the namespace;\n    - `value`: the value.\n\n### Direct use in browsers\n\nYou can simply add a tag like this:\n\n```html\n\u003cscript type=\"application/javascript\" src=\"https://www.unpkg.com/xslt-processor@3.0.0/umd/xslt-processor.js\"\u003e\u003c/script\u003e\n```\n\nAll the exports will live under `globalThis.XsltProcessor` and `window.XsltProcessor`. [See a usage example here](https://github.com/DesignLiquido/xslt-processor/blob/main/interactive-tests/xslt.html). \n\n### Breaking Changes\n\n#### Version 2\n\nUntil version 2.3.1, use like the example below:\n\n```js\nimport { Xslt, XmlParser } from 'xslt-processor'\n\n// xmlString: string of xml file contents\n// xsltString: string of xslt file contents\n// outXmlString: output xml string.\nconst xslt = new Xslt();\nconst xmlParser = new XmlParser();\nconst outXmlString = xslt.xsltProcess( // Not async.\n\txmlParser.xmlParse(xmlString),\n\txmlParser.xmlParse(xsltString)\n);\n```\n\nVersion 3 received `\u003cxsl:include\u003e` which relies on Fetch API, which is asynchronous. Version 2 doesn't support `\u003cxsl:include\u003e`.\n\nIf using Node.js older than version v17.5.0, please use version 3.2.3, that uses `node-fetch` package. Versions 3.3.0 onward require at least Node.js version v17.5.0, since they use native `fetch()` function.\n\n#### Version 1\n\nUntil version 1.2.8, use like the example below:\n\n```js\nimport { Xslt, xmlParse } from 'xslt-processor'\n\n// xmlString: string of xml file contents\n// xsltString: string of xslt file contents\n// outXmlString: output xml string.\nconst xslt = new Xslt();\nconst outXmlString = xslt.xsltProcess(\n\txmlParse(xmlString),\n\txmlParse(xsltString)\n);\n```\n\n#### Version 0\n\nUntil version 0.11.7, use like the example below:\n\n```js\nimport { xsltProcess, xmlParse } from 'xslt-processor'\n\n// xmlString: string of xml file contents\n// xsltString: string of xslt file contents\n// outXmlString: output xml string.\nconst outXmlString = xsltProcess(\n\txmlParse(xmlString),\n\txmlParse(xsltString)\n);\n```\n\nand to access the XPath parser:\n\n```js\nimport { xpathParse } from 'xslt-processor'\n```\n\nThese functions are part of `Xslt` and `XPath` classes, respectively, at version 1.x onward.\n\n## Introduction\n\nXSLT-processor contains an implementation of XSLT in JavaScript. Because XSLT uses XPath, it also contains an implementation of XPath that can be used\nindependently of XSLT. This implementation has the advantage that it makes XSLT uniformly available whenever the browser's native `XSLTProcessor()`\nis not available such as in Node.js or in web workers.\n\nXSLT-processor builds on Google's [AJAXSLT](https://github.com/4031651/ajaxslt) which was written before `XSLTProcessor()` became available in browsers, but the\ncode base has been updated to comply with ES2015+ and to make it work outside of browsers.\n\nThis implementation of XSLT operates at the DOM level on its input documents. \nIt internally uses a DOM implementation to create the output document, but usually \nreturns the output document as text stream. The DOM to construct the output document can \nbe supplied by the application, or else an internal minimal DOM implementation is used. This \nDOM comes with a minimal XML parser that can be used to generate a suitable DOM \nrepresentation of the input documents if they are present as text.\n\n## Tests and usage examples\n\nNew tests are written in Jest an can be run by calling: `npm test`.\n\nThe files `xslt.html` and `xpath.html` in the directory `interactive-tests` are interactive tests. They can be run directly from the file system; no HTTP server is needed.\nBoth interactive tests and automatic tests demonstrate the use of the library functions. There is not much more documentation so far.\n\n## Conformance\n\nA few features that are required by the XSLT and XPath standards were left out (but patches to add them are welcome).\nSee our [TODO](TODO.md) for a list of missing features that we are aware of (please add more items by means of PRs).\n\nSo far, we have implemented XQuery functions for versions 1.0 and 2.0, but this is not complete yet.\n\nIssues are also marked in the source code using throw-statements.\n\nThe DOM implementation is minimal so as to support the XSLT processing, and not intended to be complete.\n\nThe implementation is all agnostic about namespaces. It just expects XSLT elements to have tags that carry the `xsl:` prefix, but we disregard all namespace declaration for them.\n\n[There are a few nonstandard XPath functions](https://github.com/search?q=repo%3ADesignLiquido%2Fxslt-processor%20ext-\u0026type=code). \n\n### HTML Conformance\n\nHTML per se is not strict XML. Because of that, starting on version 2.0.0, this library handles HTML differently than XML:\n\n- For a document to be treated as HTML, it needs to have a `\u003c!DOCTYPE\u003e` tag defined with one of the following valid formats:\n  - `\u003c!DOCTYPE html\u003e` (for HTML5);\n  - `\u003c!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\"\u003e` (for HTML4);\n  - `\u003c!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.1//EN\" \"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd\"\u003e` (for XHTML 1.1).\n- Tags like `\u003chr\u003e`, `\u003clink\u003e` and `\u003cmeta\u003e` don't need to be closed. The output for these tags doesn't close them (adding a `/` before the tag closes, or a corresponding close tag);\n  - This rule doesn't apply for XHTML, which is strict XML.\n\n## References\n\n- XPath Specification: http://www.w3.org/TR/1999/REC-xpath-19991116\n- XSLT Specification: http://www.w3.org/TR/1999/REC-xslt-19991116\n- W3C DOM Level 3 Core Specification: http://www.w3.org/TR/2004/REC-DOM-Level-3-Core-20040407/\n- ECMAScript Language Specification: http://www.ecma-international.org/publications/standards/Ecma-262.htm\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDesignLiquido%2Fxslt-processor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FDesignLiquido%2Fxslt-processor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDesignLiquido%2Fxslt-processor/lists"}