xslt-processor 4.4.0 → 4.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +7 -1
- package/index.js +61 -18
- package/index.js.map +1 -1
- package/index.mjs +60 -6
- package/index.mjs.map +1 -1
- package/package.json +6 -16
- package/umd/xslt-processor.global.js +3 -8
- package/umd/xslt-processor.global.js.map +1 -1
package/README.md
CHANGED
|
@@ -15,6 +15,12 @@ _A JavaScript XSLT processor without native library dependencies._
|
|
|
15
15
|
<img src="https://img.shields.io/github/license/DesignLiquido/xslt-processor" />
|
|
16
16
|
</p>
|
|
17
17
|
|
|
18
|
+
## Interactive Demos
|
|
19
|
+
|
|
20
|
+
Try the XSLT and XPath processors directly in your browser:
|
|
21
|
+
|
|
22
|
+
**[🚀 Visit Interactive Demos](https://designliquido.github.io/xslt-processor/)**
|
|
23
|
+
|
|
18
24
|
## How to
|
|
19
25
|
|
|
20
26
|
Install xslt-processor using [npm](https://docs.npmjs.com/about-npm), [ohpm](https://ohpm.openharmony.cn/#/en/home) or [yarn](https://yarnpkg.com):
|
|
@@ -147,7 +153,7 @@ console.log(parsed.root.users.user); // ["Alice", "Bob"]
|
|
|
147
153
|
You can simply add a tag like this:
|
|
148
154
|
|
|
149
155
|
```html
|
|
150
|
-
<script type="application/javascript" src="https://www.unpkg.com/xslt-processor@latest/umd/xslt-processor.js"></script>
|
|
156
|
+
<script type="application/javascript" src="https://www.unpkg.com/xslt-processor@latest/umd/xslt-processor.global.js"></script>
|
|
151
157
|
```
|
|
152
158
|
|
|
153
159
|
All 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).
|
package/index.js
CHANGED
|
@@ -1,11 +1,9 @@
|
|
|
1
|
-
var __create = Object.create;
|
|
2
1
|
var __defProp = Object.defineProperty;
|
|
3
2
|
var __defProps = Object.defineProperties;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
6
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
8
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
9
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
10
8
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
11
9
|
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
@@ -36,14 +34,6 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
36
34
|
}
|
|
37
35
|
return to;
|
|
38
36
|
};
|
|
39
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
40
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
41
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
42
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
43
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
44
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
45
|
-
mod
|
|
46
|
-
));
|
|
47
37
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
48
38
|
var __async = (__this, __arguments, generator) => {
|
|
49
39
|
return new Promise((resolve, reject) => {
|
|
@@ -595,6 +585,60 @@ var init_xdocument = __esm({
|
|
|
595
585
|
}
|
|
596
586
|
});
|
|
597
587
|
|
|
588
|
+
// src/dom/html-entity-decoder.ts
|
|
589
|
+
function htmlEntityDecode(text) {
|
|
590
|
+
if (!text) {
|
|
591
|
+
return text;
|
|
592
|
+
}
|
|
593
|
+
let result = text.replace(/&([a-zA-Z]+);/g, (match, entity) => {
|
|
594
|
+
const lower = entity.toLowerCase();
|
|
595
|
+
return NAMED_ENTITIES[lower] || match;
|
|
596
|
+
});
|
|
597
|
+
result = result.replace(/&#(\d+);/g, (match, code) => {
|
|
598
|
+
try {
|
|
599
|
+
const num = parseInt(code, 10);
|
|
600
|
+
return String.fromCharCode(num);
|
|
601
|
+
} catch (e) {
|
|
602
|
+
return match;
|
|
603
|
+
}
|
|
604
|
+
});
|
|
605
|
+
result = result.replace(/&#[xX]([0-9a-fA-F]+);/g, (match, code) => {
|
|
606
|
+
try {
|
|
607
|
+
const num = parseInt(code, 16);
|
|
608
|
+
return String.fromCharCode(num);
|
|
609
|
+
} catch (e) {
|
|
610
|
+
return match;
|
|
611
|
+
}
|
|
612
|
+
});
|
|
613
|
+
return result;
|
|
614
|
+
}
|
|
615
|
+
var NAMED_ENTITIES;
|
|
616
|
+
var init_html_entity_decoder = __esm({
|
|
617
|
+
"src/dom/html-entity-decoder.ts"() {
|
|
618
|
+
NAMED_ENTITIES = {
|
|
619
|
+
"amp": "&",
|
|
620
|
+
"lt": "<",
|
|
621
|
+
"gt": ">",
|
|
622
|
+
"quot": '"',
|
|
623
|
+
"apos": "'",
|
|
624
|
+
"nbsp": "\xA0",
|
|
625
|
+
"copy": "\xA9",
|
|
626
|
+
"reg": "\xAE",
|
|
627
|
+
"times": "\xD7",
|
|
628
|
+
"divide": "\xF7",
|
|
629
|
+
"euro": "\u20AC",
|
|
630
|
+
"pound": "\xA3",
|
|
631
|
+
"yen": "\xA5",
|
|
632
|
+
"cent": "\xA2",
|
|
633
|
+
"sect": "\xA7",
|
|
634
|
+
"para": "\xB6",
|
|
635
|
+
"hellip": "\u2026",
|
|
636
|
+
"middot": "\xB7",
|
|
637
|
+
"deg": "\xB0"
|
|
638
|
+
};
|
|
639
|
+
}
|
|
640
|
+
});
|
|
641
|
+
|
|
598
642
|
// src/dom/xml-functions.ts
|
|
599
643
|
function xmlValue(node, disallowBrowserSpecificOptimization = false) {
|
|
600
644
|
if (!node) {
|
|
@@ -878,7 +922,7 @@ function xmlEscapeAttr(s) {
|
|
|
878
922
|
function xmlGetAttribute(node, name) {
|
|
879
923
|
const value = domGetAttributeValue(node, name);
|
|
880
924
|
if (value) {
|
|
881
|
-
return
|
|
925
|
+
return htmlEntityDecode(value);
|
|
882
926
|
}
|
|
883
927
|
return value;
|
|
884
928
|
}
|
|
@@ -1042,10 +1086,9 @@ function xmlToJson(node) {
|
|
|
1042
1086
|
return JSON.stringify(jsonObj);
|
|
1043
1087
|
}
|
|
1044
1088
|
}
|
|
1045
|
-
var import_he;
|
|
1046
1089
|
var init_xml_functions = __esm({
|
|
1047
1090
|
"src/dom/xml-functions.ts"() {
|
|
1048
|
-
|
|
1091
|
+
init_html_entity_decoder();
|
|
1049
1092
|
init_constants();
|
|
1050
1093
|
init_functions();
|
|
1051
1094
|
}
|
|
@@ -1091,10 +1134,10 @@ var init_xmltoken = __esm({
|
|
|
1091
1134
|
});
|
|
1092
1135
|
|
|
1093
1136
|
// src/dom/xml-parser.ts
|
|
1094
|
-
var
|
|
1137
|
+
var XmlParser;
|
|
1095
1138
|
var init_xml_parser = __esm({
|
|
1096
1139
|
"src/dom/xml-parser.ts"() {
|
|
1097
|
-
|
|
1140
|
+
init_html_entity_decoder();
|
|
1098
1141
|
init_functions();
|
|
1099
1142
|
init_xdocument();
|
|
1100
1143
|
init_xmltoken();
|
|
@@ -1185,7 +1228,7 @@ var init_xml_parser = __esm({
|
|
|
1185
1228
|
let node = domCreateElement(xmlDocument, tagName);
|
|
1186
1229
|
let attribute;
|
|
1187
1230
|
while (attribute = this.XML10_ATTRIBUTE_REGEXP.exec(text)) {
|
|
1188
|
-
const val =
|
|
1231
|
+
const val = htmlEntityDecode(attribute[5] || attribute[7] || "");
|
|
1189
1232
|
domSetAttribute(node, attribute[1], val);
|
|
1190
1233
|
}
|
|
1191
1234
|
node.siblingPosition = parent.childNodes.length;
|
|
@@ -1278,7 +1321,7 @@ var init_xml_parser = __esm({
|
|
|
1278
1321
|
let node = domCreateElement(xmlDocument, tagname);
|
|
1279
1322
|
let attribute;
|
|
1280
1323
|
while (attribute = regexAttribute.exec(text)) {
|
|
1281
|
-
const val =
|
|
1324
|
+
const val = htmlEntityDecode(attribute[5] || attribute[7] || "");
|
|
1282
1325
|
domSetAttribute(node, attribute[1], val);
|
|
1283
1326
|
}
|
|
1284
1327
|
node.siblingPosition = parent.childNodes.length;
|
|
@@ -1310,7 +1353,7 @@ var init_xml_parser = __esm({
|
|
|
1310
1353
|
} else if (!tag && char === "<") {
|
|
1311
1354
|
let text = xml.slice(start, i);
|
|
1312
1355
|
if (text && parent !== root) {
|
|
1313
|
-
domAppendChild(parent, domCreateTextNode(xmlDocument,
|
|
1356
|
+
domAppendChild(parent, domCreateTextNode(xmlDocument, htmlEntityDecode(text)));
|
|
1314
1357
|
}
|
|
1315
1358
|
if (xml.slice(i + 1, i + 4) === "!--") {
|
|
1316
1359
|
let endTagIndex = xml.slice(i + 4).indexOf("-->");
|