Skip to content

Commit 6c771c3

Browse files
Updating README.md.
1 parent b9f0122 commit 6c771c3

File tree

1 file changed

+37
-9
lines changed

1 file changed

+37
-9
lines changed

README.md

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ _A JavaScript XSLT processor without native library dependencies._
1717

1818
## How to
1919

20-
Install xslt-processor using npm or yarn:
20+
Install xslt-processor using [npm](https://docs.npmjs.com/about-npm) or [yarn](https://yarnpkg.com):
2121

2222
```sh
2323
npm install xslt-processor
@@ -27,18 +27,19 @@ npm install xslt-processor
2727
yarn add xslt-processor
2828
```
2929

30-
Within your ES2015+ code, import the `Xslt` class, the `xmlParse` function and use this way:
30+
Within your ES2015+ code, import the `Xslt` class, the `XmlParser` class and use this way:
3131

3232
```js
33-
import { Xslt, xmlParse } from 'xslt-processor'
33+
import { Xslt, XmlParser } from 'xslt-processor'
3434

3535
// xmlString: string of xml file contents
3636
// xsltString: string of xslt file contents
3737
// outXmlString: output xml string.
3838
const xslt = new Xslt();
39+
const xmlParser = new XmlParser();
3940
const outXmlString = xslt.xsltProcess(
40-
xmlParse(xmlString),
41-
xmlParse(xsltString)
41+
xmlParser.xmlParse(xmlString),
42+
xmlParser.xmlParse(xsltString)
4243
);
4344
```
4445

@@ -67,13 +68,15 @@ You can pass an `options` object to `Xslt` class:
6768
const options = {
6869
escape: false,
6970
selfClosingTags: true,
70-
parameters: [{ name: 'myparam', value: '123' }]
71+
parameters: [{ name: 'myparam', value: '123' }],
72+
outputMethod: 'xml'
7173
};
7274
const xslt = new Xslt(options);
7375
```
7476

7577
- `escape` (`boolean`, default `true`): replaces symbols like `<`, `>`, `&` and `"` by the corresponding [XML entities](https://www.tutorialspoint.com/xml/xml_character_entities.htm).
7678
- `selfClosingTags` (`boolean`, default `true`): Self-closes tags that don't have inner elements, if `true`. For instance, `<test></test>` becomes `<test />`.
79+
- `outputMethod` (`string`, default `xml`): Specifies the default output method. if `<xsl:output>` is declared in your XSLT file, this will be overridden.
7780
- `parameters` (`array`, default `[]`): external parameters that you want to use.
7881
- `name`: the parameter name;
7982
- `namespaceUri` (optional): the namespace;
@@ -84,13 +87,32 @@ const xslt = new Xslt(options);
8487
You can simply add a tag like this:
8588

8689
```html
87-
<script type="application/javascript" src="https://www.unpkg.com/xslt-processor@1.2.0/umd/xslt-processor.js"></script>
90+
<script type="application/javascript" src="https://www.unpkg.com/xslt-processor@2.0.0/umd/xslt-processor.js"></script>
8891
```
8992

9093
All the exports will live under `globalThis.XsltProcessor`. [See a usage example here](https://github.com/DesignLiquido/xslt-processor/blob/main/interactive-tests/xslt.html).
9194

9295
### Breaking Changes
9396

97+
#### Version 1
98+
99+
Until version 1.2.8, use like the example below:
100+
101+
```js
102+
import { Xslt, xmlParse } from 'xslt-processor'
103+
104+
// xmlString: string of xml file contents
105+
// xsltString: string of xslt file contents
106+
// outXmlString: output xml string.
107+
const xslt = new Xslt();
108+
const outXmlString = xslt.xsltProcess(
109+
xmlParse(xmlString),
110+
xmlParse(xsltString)
111+
);
112+
```
113+
114+
#### Version 0
115+
94116
Until version 0.11.7, use like the example below:
95117

96118
```js
@@ -135,7 +157,6 @@ used. This DOM comes with a minimal XML parser that can be used to
135157
generate a suitable DOM representation of the input documents if they
136158
are present as text.
137159

138-
139160
## Tests and usage examples
140161

141162
New tests are written in Jest an can be run by calling: `npm test`.
@@ -155,7 +176,14 @@ The DOM implementation is minimal so as to support the XSLT processing, and not
155176
The implementation is all agnostic about namespaces. It just expects
156177
XSLT elements to have tags that carry the `xsl:` prefix, but we disregard all namespace declaration for them.
157178

158-
There are a few nonstandard XPath functions. Grep `xpath.js` for `ext-` to see their definitions.
179+
[There are a few nonstandard XPath functions](https://github.com/search?q=repo%3ADesignLiquido%2Fxslt-processor%20ext-&type=code).
180+
181+
### HTML Conformance
182+
183+
HTML per se is not strict XML. Because of that, starting on version 2.0.0, this library handles HTML differently than XML:
184+
185+
- Tags like `<hr>`, `<link>` and `<meta>` 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);
186+
- This rule doesn't apply for XHTML, which is strict XML.
159187

160188
## References
161189

0 commit comments

Comments
 (0)