xslt-processor 4.8.2 → 4.8.3
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 +47 -1
- package/index.js +2 -1
- package/index.js.map +1 -1
- package/index.mjs +2 -1
- package/index.mjs.map +1 -1
- package/package.json +1 -1
- package/umd/xslt-processor.global.js +1 -1
- package/umd/xslt-processor.global.js.map +1 -1
package/README.md
CHANGED
|
@@ -80,7 +80,7 @@ const xslt = new Xslt(options);
|
|
|
80
80
|
- `cData` (`boolean`, default `true`): resolves CDATA elements in the output. Content under CDATA is resolved as text. This overrides `escape` for CDATA content.
|
|
81
81
|
- `escape` (`boolean`, default `true`): replaces symbols like `<`, `>`, `&` 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 `>` and `<` by `<` and `>`, respectively.
|
|
82
82
|
- `selfClosingTags` (`boolean`, default `true`): Self-closes tags that don't have inner elements, if `true`. For instance, `<test></test>` becomes `<test />`.
|
|
83
|
-
- `outputMethod` (`string`, default `xml`): Specifies the default output method. if `<xsl:output>` is declared in your XSLT file, this will be overridden. Valid values: `xml`, `html`, `text`, `name`, `xhtml`, `json`.
|
|
83
|
+
- `outputMethod` (`string`, default `xml`): Specifies the default output method. if `<xsl:output>` is declared in your XSLT file, this will be overridden. Valid values: `xml`, `html`, `text`, `name`, `xhtml`, `json`, `adaptive`.
|
|
84
84
|
- `parameters` (`array`, default `[]`): external parameters that you want to use.
|
|
85
85
|
- `name`: the parameter name;
|
|
86
86
|
- `namespaceUri` (optional): the namespace;
|
|
@@ -131,6 +131,52 @@ console.log(parsed.root.users.user); // ["Alice", "Bob"]
|
|
|
131
131
|
- Attributes are prefixed with `@` (when present in the output)
|
|
132
132
|
- Mixed text and element content uses the `#text` property for text nodes
|
|
133
133
|
|
|
134
|
+
#### Adaptive Output Format
|
|
135
|
+
|
|
136
|
+
When using `outputMethod: 'adaptive'`, the XSLT processor automatically detects the most appropriate output format based on the transformation result. This implements XSLT 3.1 adaptive output behavior.
|
|
137
|
+
|
|
138
|
+
**Detection Rules:**
|
|
139
|
+
|
|
140
|
+
- If the output contains only text nodes (no elements), it returns as plain text
|
|
141
|
+
- If the output contains one or more elements, it returns as XML
|
|
142
|
+
|
|
143
|
+
**Example:**
|
|
144
|
+
|
|
145
|
+
```js
|
|
146
|
+
const xslt = new Xslt({ outputMethod: 'adaptive' });
|
|
147
|
+
const xmlParser = new XmlParser();
|
|
148
|
+
|
|
149
|
+
// Example 1: Pure text output
|
|
150
|
+
const xmlString1 = `<root><value>Hello World</value></root>`;
|
|
151
|
+
const xsltString1 = `<?xml version="1.0"?>
|
|
152
|
+
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
|
153
|
+
<xsl:template match="/">
|
|
154
|
+
<xsl:value-of select="root/value"/>
|
|
155
|
+
</xsl:template>
|
|
156
|
+
</xsl:stylesheet>`;
|
|
157
|
+
|
|
158
|
+
const result1 = await xslt.xsltProcess(
|
|
159
|
+
xmlParser.xmlParse(xmlString1),
|
|
160
|
+
xmlParser.xmlParse(xsltString1)
|
|
161
|
+
);
|
|
162
|
+
console.log(result1); // "Hello World" (plain text)
|
|
163
|
+
|
|
164
|
+
// Example 2: XML output
|
|
165
|
+
const xmlString2 = `<root><user>John</user></root>`;
|
|
166
|
+
const xsltString2 = `<?xml version="1.0"?>
|
|
167
|
+
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
|
168
|
+
<xsl:template match="/">
|
|
169
|
+
<users><xsl:copy-of select="root/user"/></users>
|
|
170
|
+
</xsl:template>
|
|
171
|
+
</xsl:stylesheet>`;
|
|
172
|
+
|
|
173
|
+
const result2 = await xslt.xsltProcess(
|
|
174
|
+
xmlParser.xmlParse(xmlString2),
|
|
175
|
+
xmlParser.xmlParse(xsltString2)
|
|
176
|
+
);
|
|
177
|
+
console.log(result2); // "<users><user>John</user></users>" (XML)
|
|
178
|
+
```
|
|
179
|
+
|
|
134
180
|
### Direct use in browsers
|
|
135
181
|
|
|
136
182
|
You can simply add a tag like this:
|
package/index.js
CHANGED
|
@@ -14747,8 +14747,9 @@ var Xslt = class {
|
|
|
14747
14747
|
if (useAttributeSets) {
|
|
14748
14748
|
yield this.applyAttributeSets(context, node, useAttributeSets);
|
|
14749
14749
|
}
|
|
14750
|
+
node.siblingPosition = (output || this.outputDocument).childNodes.length;
|
|
14750
14751
|
domAppendChild(output || this.outputDocument, node);
|
|
14751
|
-
const clonedContext = context.clone(
|
|
14752
|
+
const clonedContext = context.clone();
|
|
14752
14753
|
yield this.xsltChildNodes(clonedContext, template, node);
|
|
14753
14754
|
});
|
|
14754
14755
|
}
|