xslt-processor
Advanced tools
Comparing version 1.2.8 to 2.0.0
@@ -15,8 +15,1 @@ import { XDocument } from "./xdocument"; | ||
export declare function domCreateDTDSection(doc: XDocument, data: any): XNode; | ||
/** | ||
* Parses the given XML string with our custom, JavaScript XML parser | ||
* @param xml The XML String. | ||
* @returns A XDocument. | ||
* @author Steffen Meschkat <mesch@google.com> | ||
*/ | ||
export declare function xmlParse(xml: string): XDocument; |
"use strict"; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.xmlParse = exports.domCreateDTDSection = exports.domCreateDocumentFragment = exports.domCreateComment = exports.domCreateCDATASection = exports.domCreateElement = exports.domCreateTransformedTextNode = exports.domCreateTextNode = exports.domAppendTransformedChild = exports.domAppendChild = exports.domSetTransformedAttribute = exports.domSetAttribute = exports.domGetAttributeValue = void 0; | ||
// Copyright 2023 Design Liquido | ||
@@ -11,15 +6,4 @@ // Copyright 2018 Johannes Wilm | ||
// All Rights Reserved | ||
// | ||
// Original author: Steffen Meschkat <mesch@google.com> | ||
// | ||
// An XML parse and a minimal DOM implementation that just supports | ||
// the subset of the W3C DOM that is used in the XSLT implementation. | ||
var he_1 = __importDefault(require("he")); | ||
var util_1 = require("./util"); | ||
var xdocument_1 = require("./xdocument"); | ||
var xmltoken_1 = require("./xmltoken"); | ||
var XML10_TAGNAME_REGEXP = new RegExp("^(".concat(xmltoken_1.XML10_NAME, ")")); | ||
var XML10_ATTRIBUTE_REGEXP = new RegExp(xmltoken_1.XML10_ATTRIBUTE, 'g'); | ||
var XML11_TAGNAME_REGEXP = new RegExp("^(".concat(xmltoken_1.XML11_NAME, ")")); | ||
var XML11_ATTRIBUTE_REGEXP = new RegExp(xmltoken_1.XML11_ATTRIBUTE, 'g'); | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.domCreateDTDSection = exports.domCreateDocumentFragment = exports.domCreateComment = exports.domCreateCDATASection = exports.domCreateElement = exports.domCreateTransformedTextNode = exports.domCreateTextNode = exports.domAppendTransformedChild = exports.domAppendChild = exports.domSetTransformedAttribute = exports.domSetAttribute = exports.domGetAttributeValue = void 0; | ||
// Wrapper around DOM methods so we can condense their invocations. | ||
@@ -74,149 +58,3 @@ function domGetAttributeValue(node, name) { | ||
exports.domCreateDTDSection = domCreateDTDSection; | ||
/** | ||
* Parses the given XML string with our custom, JavaScript XML parser | ||
* @param xml The XML String. | ||
* @returns A XDocument. | ||
* @author Steffen Meschkat <mesch@google.com> | ||
*/ | ||
function xmlParse(xml) { | ||
var regexEmpty = /\/$/; | ||
var regexTagname; | ||
var regexAttribute; | ||
if (xml.match(/^<\?xml/)) { | ||
// When an XML document begins with an XML declaration | ||
// VersionInfo must appear. | ||
if (xml.search(new RegExp(xmltoken_1.XML10_VERSION_INFO)) == 5) { | ||
regexTagname = XML10_TAGNAME_REGEXP; | ||
regexAttribute = XML10_ATTRIBUTE_REGEXP; | ||
} | ||
else if (xml.search(new RegExp(xmltoken_1.XML11_VERSION_INFO)) == 5) { | ||
regexTagname = XML11_TAGNAME_REGEXP; | ||
regexAttribute = XML11_ATTRIBUTE_REGEXP; | ||
} | ||
else { | ||
// VersionInfo is missing, or unknown version number. | ||
// TODO : Fallback to XML 1.0 or XML 1.1, or just return null? | ||
throw new Error('VersionInfo is missing, or unknown version number.'); | ||
} | ||
} | ||
else { | ||
// When an XML declaration is missing it's an XML 1.0 document. | ||
regexTagname = XML10_TAGNAME_REGEXP; | ||
regexAttribute = XML10_ATTRIBUTE_REGEXP; | ||
} | ||
var xmldoc = new xdocument_1.XDocument(); | ||
var root = xmldoc; | ||
var stack = []; | ||
var parent = root; | ||
stack.push(parent); | ||
var tag = false, quotes = false, doublequotes = false, start = 0; | ||
for (var i = 0; i < xml.length; ++i) { | ||
var char = xml.charAt(i); | ||
if (tag && !doublequotes && char === "'") { | ||
quotes = !quotes; | ||
} | ||
else if (tag && !quotes && char === '"') { | ||
doublequotes = !doublequotes; | ||
} | ||
else if (tag && char === '>' && !quotes && !doublequotes) { | ||
var text = xml.slice(start, i); | ||
if (text.charAt(0) == '/') { | ||
stack.pop(); | ||
parent = stack[stack.length - 1]; | ||
} | ||
else if (text.charAt(0) === '?') { | ||
// Ignore XML declaration and processing instructions | ||
} | ||
else if (text.charAt(0) === '!') { | ||
// Ignore comments | ||
// console.log(`Ignored ${text}`); | ||
} | ||
else { | ||
var empty = text.match(regexEmpty); | ||
var tagname = regexTagname.exec(text)[1]; | ||
var node = domCreateElement(xmldoc, tagname); | ||
var attribute = void 0; | ||
while ((attribute = regexAttribute.exec(text))) { | ||
var val = he_1.default.decode(attribute[5] || attribute[7] || ''); | ||
domSetAttribute(node, attribute[1], val); | ||
} | ||
node.siblingPosition = parent.childNodes.length; | ||
domAppendChild(parent, node); | ||
if (!empty) { | ||
parent = node; | ||
stack.push(node); | ||
} | ||
var namespaceMap = (0, util_1.namespaceMapAt)(node); | ||
if (node.prefix !== null) { | ||
if (node.prefix in namespaceMap) | ||
node.namespaceUri = namespaceMap[node.prefix]; | ||
// else, prefix is undefined. do anything? | ||
} | ||
else { | ||
if ('' in namespaceMap) | ||
node.namespaceUri = namespaceMap['']; | ||
} | ||
for (var i_1 = 0; i_1 < node.attributes.length; ++i_1) { | ||
if (node.attributes[i_1].prefix !== null) { | ||
if (node.attributes[i_1].prefix in namespaceMap) { | ||
node.attributes[i_1].namespaceUri = namespaceMap[node.attributes[i_1].prefix]; | ||
} | ||
// else, prefix undefined. | ||
} | ||
// elements with no prefix always have no namespace, so do nothing here. | ||
} | ||
} | ||
start = i + 1; | ||
tag = false; | ||
quotes = false; | ||
doublequotes = false; | ||
} | ||
else if (!tag && char === '<') { | ||
var text = xml.slice(start, i); | ||
if (text && parent !== root) { | ||
domAppendChild(parent, domCreateTextNode(xmldoc, text)); | ||
} | ||
if (xml.slice(i + 1, i + 4) === '!--') { | ||
var endTagIndex = xml.slice(i + 4).indexOf('-->'); | ||
if (endTagIndex) { | ||
var node = domCreateComment(xmldoc, xml.slice(i + 4, i + endTagIndex + 4)); | ||
domAppendChild(parent, node); | ||
i += endTagIndex + 6; | ||
} | ||
} | ||
else if (xml.slice(i + 1, i + 9) === '![CDATA[') { | ||
var endTagIndex = xml.slice(i + 9).indexOf(']]>'); | ||
if (endTagIndex) { | ||
var node = domCreateCDATASection(xmldoc, xml.slice(i + 9, i + endTagIndex + 9)); | ||
domAppendChild(parent, node); | ||
i += endTagIndex + 11; | ||
} | ||
} | ||
else if (xml.slice(i + 1, i + 9) === '!DOCTYPE') { | ||
var endTagIndex = xml.slice(i + 9).indexOf('>'); | ||
if (endTagIndex) { | ||
var dtdValue = xml.slice(i + 9, i + endTagIndex + 9).trimStart(); | ||
// TODO: Not sure if this is a good solution. | ||
// Trying to implement this: https://github.com/DesignLiquido/xslt-processor/issues/30 | ||
var node = void 0; | ||
if (parent.nodeName === 'xsl:text') { | ||
node = domCreateTextNode(xmldoc, "<!DOCTYPE ".concat(dtdValue, ">")); | ||
} | ||
else { | ||
node = domCreateDTDSection(xmldoc, dtdValue); | ||
} | ||
domAppendChild(parent, node); | ||
i += endTagIndex + dtdValue.length + 5; | ||
} | ||
} | ||
else { | ||
tag = true; | ||
} | ||
start = i + 1; | ||
} | ||
} | ||
return root; | ||
} | ||
exports.xmlParse = xmlParse; | ||
//XDocument.prototype = new XNode(DOM_DOCUMENT_NODE, '#document'); | ||
//# sourceMappingURL=functions.js.map |
@@ -5,2 +5,3 @@ export * from './functions'; | ||
export * from './xml-output-options'; | ||
export * from './xml-parser'; | ||
export * from './xnode'; |
@@ -21,3 +21,4 @@ "use strict"; | ||
__exportStar(require("./xml-output-options"), exports); | ||
__exportStar(require("./xml-parser"), exports); | ||
__exportStar(require("./xnode"), exports); | ||
//# sourceMappingURL=index.js.map |
@@ -8,5 +8,1 @@ export declare function mapExec(array: any[], func: Function): void; | ||
export declare function reverseInPlace(array: any[]): void; | ||
export declare function namespaceMapAt(node: any): { | ||
xmlns: string; | ||
xml: string; | ||
}; |
@@ -12,3 +12,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.namespaceMapAt = exports.reverseInPlace = exports.mapExpr = exports.mapExec = void 0; | ||
exports.reverseInPlace = exports.mapExpr = exports.mapExec = void 0; | ||
// Applies the given function to each element of the array, preserving | ||
@@ -45,28 +45,2 @@ // this, and passing the index. | ||
exports.reverseInPlace = reverseInPlace; | ||
// (viat) given an XNode (see dom.js), returns an object mapping prefixes to their corresponding namespaces in its scope. | ||
// default namespace is treated as if its prefix were the empty string. | ||
function namespaceMapAt(node) { | ||
var map = { | ||
// reserved namespaces https://www.w3.org/TR/REC-xml-names/#xmlReserved | ||
xmlns: 'http://www.w3.org/2000/xmlns/', | ||
xml: 'http://www.w3.org/XML/1998/namespace' | ||
}; | ||
var n = node; | ||
while (n !== null) { | ||
for (var i = 0; i < n.attributes.length; i++) { | ||
if (n.attributes[i].nodeName.startsWith('xmlns:')) { | ||
var prefix = n.attributes[i].nodeName.split(':')[1]; | ||
if (!(prefix in map)) | ||
map[prefix] = n.attributes[i].nodeValue; | ||
} | ||
else if (n.attributes[i].nodeName == 'xmlns') { | ||
if (!('' in map)) | ||
map[''] = n.attributes[i].nodeValue || null; | ||
} | ||
} | ||
n = n.parentNode; | ||
} | ||
return map; | ||
} | ||
exports.namespaceMapAt = namespaceMapAt; | ||
//# sourceMappingURL=util.js.map |
import { XNode } from './xnode'; | ||
import { XDocument } from './xdocument'; | ||
import { XmlOutputOptions } from './xml-output-options'; | ||
export declare function xmlValue(node: any, disallowBrowserSpecificOptimization?: boolean): any; | ||
/** | ||
* Returns the text value of a node; for nodes without children this | ||
* is the nodeValue, for nodes with children this is the concatenation | ||
* of the value of all children. Browser-specific optimizations are used by | ||
* default; they can be disabled by passing "true" in as the second parameter. | ||
* @param node The Node (not exactly a `XNode` here). | ||
* @param disallowBrowserSpecificOptimization A boolean, to avoid browser optimization. | ||
* @returns The XML value as a string. | ||
*/ | ||
export declare function xmlValue(node: any, disallowBrowserSpecificOptimization?: boolean): string; | ||
export declare function xmlValue2(node: any, disallowBrowserSpecificOptimization?: boolean): any; | ||
/** | ||
* Returns the representation of a node as XML text. | ||
* In general it is not used by XSLT, that uses `xmlTransformedText` instead. | ||
* @param {XNode} node The starting node. | ||
* @param {XmlOutputOptions} options XML output options. | ||
* @returns The XML string. | ||
* @see xmlTransformedText | ||
*/ | ||
@@ -38,3 +49,3 @@ export declare function xmlText(node: XNode, options?: XmlOutputOptions): string; | ||
*/ | ||
export declare function xmlGetAttribute(node: XNode, name: string): any; | ||
export declare function xmlGetAttribute(node: XNode, name: string): string; | ||
/** | ||
@@ -41,0 +52,0 @@ * Wrapper function to access the owner document uniformly for document |
@@ -10,6 +10,11 @@ "use strict"; | ||
var functions_1 = require("./functions"); | ||
// Returns the text value of a node; for nodes without children this | ||
// is the nodeValue, for nodes with children this is the concatenation | ||
// of the value of all children. Browser-specific optimizations are used by | ||
// default; they can be disabled by passing "true" in as the second parameter. | ||
/** | ||
* Returns the text value of a node; for nodes without children this | ||
* is the nodeValue, for nodes with children this is the concatenation | ||
* of the value of all children. Browser-specific optimizations are used by | ||
* default; they can be disabled by passing "true" in as the second parameter. | ||
* @param node The Node (not exactly a `XNode` here). | ||
* @param disallowBrowserSpecificOptimization A boolean, to avoid browser optimization. | ||
* @returns The XML value as a string. | ||
*/ | ||
function xmlValue(node, disallowBrowserSpecificOptimization) { | ||
@@ -21,35 +26,36 @@ if (disallowBrowserSpecificOptimization === void 0) { disallowBrowserSpecificOptimization = false; } | ||
var ret = ''; | ||
if (node.nodeType == constants_1.DOM_TEXT_NODE || node.nodeType == constants_1.DOM_CDATA_SECTION_NODE) { | ||
ret += node.nodeValue; | ||
} | ||
else if (node.nodeType == constants_1.DOM_ATTRIBUTE_NODE) { | ||
ret += node.nodeValue; | ||
} | ||
else if (node.nodeType == constants_1.DOM_ELEMENT_NODE || | ||
node.nodeType == constants_1.DOM_DOCUMENT_NODE || | ||
node.nodeType == constants_1.DOM_DOCUMENT_FRAGMENT_NODE) { | ||
if (!disallowBrowserSpecificOptimization) { | ||
// IE, Safari, Opera, and friends | ||
var innerText = node.innerText; | ||
if (innerText != undefined) { | ||
return innerText; | ||
switch (node.nodeType) { | ||
case constants_1.DOM_DOCUMENT_TYPE_NODE: | ||
return "<!DOCTYPE ".concat(node.nodeValue, ">"); | ||
case constants_1.DOM_TEXT_NODE: | ||
case constants_1.DOM_CDATA_SECTION_NODE: | ||
case constants_1.DOM_ATTRIBUTE_NODE: | ||
return node.nodeValue; | ||
case constants_1.DOM_ELEMENT_NODE: | ||
case constants_1.DOM_DOCUMENT_NODE: | ||
case constants_1.DOM_DOCUMENT_FRAGMENT_NODE: | ||
if (!disallowBrowserSpecificOptimization) { | ||
// IE, Safari, Opera, and friends | ||
var innerText = node.innerText; | ||
if (innerText != undefined) { | ||
return innerText; | ||
} | ||
// Firefox | ||
var textContent = node.textContent; | ||
if (textContent != undefined) { | ||
return textContent; | ||
} | ||
} | ||
// Firefox | ||
var textContent = node.textContent; | ||
if (textContent != undefined) { | ||
return textContent; | ||
if (node.transformedChildNodes.length > 0) { | ||
for (var i = 0; i < node.transformedChildNodes.length; ++i) { | ||
ret += xmlValue(node.transformedChildNodes[i]); | ||
} | ||
} | ||
} | ||
if (node.transformedChildNodes.length > 0) { | ||
for (var i = 0; i < node.transformedChildNodes.length; ++i) { | ||
ret += xmlValue(node.transformedChildNodes[i]); | ||
else { | ||
for (var i = 0; i < node.childNodes.length; ++i) { | ||
ret += xmlValue(node.childNodes[i]); | ||
} | ||
} | ||
} | ||
else { | ||
for (var i = 0; i < node.childNodes.length; ++i) { | ||
ret += xmlValue(node.childNodes[i]); | ||
} | ||
} | ||
return ret; | ||
} | ||
return ret; | ||
} | ||
@@ -96,5 +102,7 @@ exports.xmlValue = xmlValue; | ||
* Returns the representation of a node as XML text. | ||
* In general it is not used by XSLT, that uses `xmlTransformedText` instead. | ||
* @param {XNode} node The starting node. | ||
* @param {XmlOutputOptions} options XML output options. | ||
* @returns The XML string. | ||
* @see xmlTransformedText | ||
*/ | ||
@@ -105,3 +113,4 @@ function xmlText(node, options) { | ||
escape: true, | ||
selfClosingTags: true | ||
selfClosingTags: true, | ||
outputMethod: 'xml' | ||
}; } | ||
@@ -137,3 +146,3 @@ var buffer = []; | ||
if (node.childNodes.length === 0) { | ||
if (options.selfClosingTags) { | ||
if (options.selfClosingTags || (options.outputMethod === 'html' && ['hr', 'link'].includes(node.nodeName))) { | ||
buffer.push('/>'); | ||
@@ -169,3 +178,4 @@ } | ||
escape: true, | ||
selfClosingTags: true | ||
selfClosingTags: true, | ||
outputMethod: 'xml' | ||
}; } | ||
@@ -182,3 +192,3 @@ var buffer = []; | ||
var nodeValue = node.transformedNodeValue || node.nodeValue; | ||
if (nodeType == constants_1.DOM_TEXT_NODE) { | ||
if (nodeType === constants_1.DOM_TEXT_NODE) { | ||
if (node.transformedNodeValue && node.transformedNodeValue.trim() !== '') { | ||
@@ -191,3 +201,3 @@ var finalText = node.escape && options.escape ? | ||
} | ||
else if (nodeType == constants_1.DOM_CDATA_SECTION_NODE) { | ||
else if (nodeType === constants_1.DOM_CDATA_SECTION_NODE) { | ||
if (options.cData) { | ||
@@ -214,3 +224,3 @@ buffer.push(nodeValue); | ||
} | ||
else if (nodeType == constants_1.DOM_DOCUMENT_NODE || nodeType == constants_1.DOM_DOCUMENT_FRAGMENT_NODE) { | ||
else if (nodeType === constants_1.DOM_DOCUMENT_NODE || nodeType === constants_1.DOM_DOCUMENT_FRAGMENT_NODE) { | ||
var childNodes = node.transformedChildNodes.concat(node.childNodes); | ||
@@ -245,3 +255,6 @@ childNodes.sort(function (a, b) { return a.siblingPosition - b.siblingPosition; }); | ||
if (childNodes.length === 0) { | ||
if (options.selfClosingTags) { | ||
if (options.outputMethod === 'html' && ['hr', 'link', 'meta'].includes(node.nodeName)) { | ||
buffer.push('>'); | ||
} | ||
else if (options.selfClosingTags) { | ||
buffer.push('/>'); | ||
@@ -276,2 +289,8 @@ } | ||
} | ||
/** | ||
* Gets the full node name. | ||
* When namespace is set, the node name is `namespace:node`. | ||
* @param node The node. | ||
* @returns The full node name as a string. | ||
*/ | ||
function xmlFullNodeName(node) { | ||
@@ -278,0 +297,0 @@ var nodeName = node.transformedNodeName || node.nodeName; |
@@ -5,2 +5,3 @@ export type XmlOutputOptions = { | ||
selfClosingTags: boolean; | ||
outputMethod: 'xml' | 'html' | 'text' | 'name'; | ||
}; |
export { XPath } from './xpath'; | ||
export { Xslt, XsltOptions } from './xslt'; | ||
export { xmlParse, xmlEscapeText } from './dom'; | ||
export { XmlParser, xmlEscapeText } from './dom'; | ||
export { ExprContext } from './xpath'; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.ExprContext = exports.xmlEscapeText = exports.xmlParse = exports.Xslt = exports.XPath = void 0; | ||
exports.ExprContext = exports.xmlEscapeText = exports.XmlParser = exports.Xslt = exports.XPath = void 0; | ||
var xpath_1 = require("./xpath"); | ||
@@ -9,3 +9,3 @@ Object.defineProperty(exports, "XPath", { enumerable: true, get: function () { return xpath_1.XPath; } }); | ||
var dom_1 = require("./dom"); | ||
Object.defineProperty(exports, "xmlParse", { enumerable: true, get: function () { return dom_1.xmlParse; } }); | ||
Object.defineProperty(exports, "XmlParser", { enumerable: true, get: function () { return dom_1.XmlParser; } }); | ||
Object.defineProperty(exports, "xmlEscapeText", { enumerable: true, get: function () { return dom_1.xmlEscapeText; } }); | ||
@@ -12,0 +12,0 @@ var xpath_2 = require("./xpath"); |
{ | ||
"name": "xslt-processor", | ||
"version": "1.2.8", | ||
"version": "2.0.0", | ||
"description": "A JavaScript XSLT Processor", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -20,3 +20,3 @@ # XSLT-processor | ||
Install xslt-processor using npm or yarn: | ||
Install xslt-processor using [npm](https://docs.npmjs.com/about-npm) or [yarn](https://yarnpkg.com): | ||
@@ -31,6 +31,6 @@ ```sh | ||
Within your ES2015+ code, import the `Xslt` class, the `xmlParse` function and use this way: | ||
Within your ES2015+ code, import the `Xslt` class, the `XmlParser` class and use this way: | ||
```js | ||
import { Xslt, xmlParse } from 'xslt-processor' | ||
import { Xslt, XmlParser } from 'xslt-processor' | ||
@@ -41,5 +41,6 @@ // xmlString: string of xml file contents | ||
const xslt = new Xslt(); | ||
const xmlParser = new XmlParser(); | ||
const outXmlString = xslt.xsltProcess( | ||
xmlParse(xmlString), | ||
xmlParse(xsltString) | ||
xmlParser.xmlParse(xmlString), | ||
xmlParser.xmlParse(xsltString) | ||
); | ||
@@ -73,3 +74,4 @@ ``` | ||
selfClosingTags: true, | ||
parameters: [{ name: 'myparam', value: '123' }] | ||
parameters: [{ name: 'myparam', value: '123' }], | ||
outputMethod: 'xml' | ||
}; | ||
@@ -81,2 +83,3 @@ const xslt = new Xslt(options); | ||
- `selfClosingTags` (`boolean`, default `true`): Self-closes tags that don't have inner elements, if `true`. For instance, `<test></test>` becomes `<test />`. | ||
- `outputMethod` (`string`, default `xml`): Specifies the default output method. if `<xsl:output>` is declared in your XSLT file, this will be overridden. | ||
- `parameters` (`array`, default `[]`): external parameters that you want to use. | ||
@@ -92,3 +95,3 @@ - `name`: the parameter name; | ||
```html | ||
<script type="application/javascript" src="https://www.unpkg.com/xslt-processor@1.2.0/umd/xslt-processor.js"></script> | ||
<script type="application/javascript" src="https://www.unpkg.com/xslt-processor@2.0.0/umd/xslt-processor.js"></script> | ||
``` | ||
@@ -100,2 +103,21 @@ | ||
#### Version 1 | ||
Until version 1.2.8, use like the example below: | ||
```js | ||
import { Xslt, xmlParse } from 'xslt-processor' | ||
// xmlString: string of xml file contents | ||
// xsltString: string of xslt file contents | ||
// outXmlString: output xml string. | ||
const xslt = new Xslt(); | ||
const outXmlString = xslt.xsltProcess( | ||
xmlParse(xmlString), | ||
xmlParse(xsltString) | ||
); | ||
``` | ||
#### Version 0 | ||
Until version 0.11.7, use like the example below: | ||
@@ -145,3 +167,2 @@ | ||
## Tests and usage examples | ||
@@ -166,4 +187,11 @@ | ||
There are a few nonstandard XPath functions. Grep `xpath.js` for `ext-` to see their definitions. | ||
[There are a few nonstandard XPath functions](https://github.com/search?q=repo%3ADesignLiquido%2Fxslt-processor%20ext-&type=code). | ||
### HTML Conformance | ||
HTML per se is not strict XML. Because of that, starting on version 2.0.0, this library handles HTML differently than XML: | ||
- 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); | ||
- This rule doesn't apply for XHTML, which is strict XML. | ||
## References | ||
@@ -170,0 +198,0 @@ |
@@ -15,8 +15,1 @@ import { XDocument } from "./xdocument"; | ||
export declare function domCreateDTDSection(doc: XDocument, data: any): XNode; | ||
/** | ||
* Parses the given XML string with our custom, JavaScript XML parser | ||
* @param xml The XML String. | ||
* @returns A XDocument. | ||
* @author Steffen Meschkat <mesch@google.com> | ||
*/ | ||
export declare function xmlParse(xml: string): XDocument; |
@@ -5,2 +5,3 @@ export * from './functions'; | ||
export * from './xml-output-options'; | ||
export * from './xml-parser'; | ||
export * from './xnode'; |
@@ -8,5 +8,1 @@ export declare function mapExec(array: any[], func: Function): void; | ||
export declare function reverseInPlace(array: any[]): void; | ||
export declare function namespaceMapAt(node: any): { | ||
xmlns: string; | ||
xml: string; | ||
}; |
import { XNode } from './xnode'; | ||
import { XDocument } from './xdocument'; | ||
import { XmlOutputOptions } from './xml-output-options'; | ||
export declare function xmlValue(node: any, disallowBrowserSpecificOptimization?: boolean): any; | ||
/** | ||
* Returns the text value of a node; for nodes without children this | ||
* is the nodeValue, for nodes with children this is the concatenation | ||
* of the value of all children. Browser-specific optimizations are used by | ||
* default; they can be disabled by passing "true" in as the second parameter. | ||
* @param node The Node (not exactly a `XNode` here). | ||
* @param disallowBrowserSpecificOptimization A boolean, to avoid browser optimization. | ||
* @returns The XML value as a string. | ||
*/ | ||
export declare function xmlValue(node: any, disallowBrowserSpecificOptimization?: boolean): string; | ||
export declare function xmlValue2(node: any, disallowBrowserSpecificOptimization?: boolean): any; | ||
/** | ||
* Returns the representation of a node as XML text. | ||
* In general it is not used by XSLT, that uses `xmlTransformedText` instead. | ||
* @param {XNode} node The starting node. | ||
* @param {XmlOutputOptions} options XML output options. | ||
* @returns The XML string. | ||
* @see xmlTransformedText | ||
*/ | ||
@@ -38,3 +49,3 @@ export declare function xmlText(node: XNode, options?: XmlOutputOptions): string; | ||
*/ | ||
export declare function xmlGetAttribute(node: XNode, name: string): any; | ||
export declare function xmlGetAttribute(node: XNode, name: string): string; | ||
/** | ||
@@ -41,0 +52,0 @@ * Wrapper function to access the owner document uniformly for document |
@@ -5,2 +5,3 @@ export type XmlOutputOptions = { | ||
selfClosingTags: boolean; | ||
outputMethod: 'xml' | 'html' | 'text' | 'name'; | ||
}; |
export { XPath } from './xpath'; | ||
export { Xslt, XsltOptions } from './xslt'; | ||
export { xmlParse, xmlEscapeText } from './dom'; | ||
export { XmlParser, xmlEscapeText } from './dom'; | ||
export { ExprContext } from './xpath'; |
@@ -7,3 +7,3 @@ import { XNode } from "../../dom"; | ||
constructor(value: any); | ||
stringValue(): any; | ||
stringValue(): string; | ||
booleanValue(): boolean; | ||
@@ -10,0 +10,0 @@ numberValue(): number; |
@@ -36,3 +36,3 @@ import { XDocument, XNode } from '../dom'; | ||
outputDocument: XDocument; | ||
outputMethod: string; | ||
outputMethod: 'xml' | 'html' | 'text' | 'name'; | ||
outputOmitXmlDeclaration: string; | ||
@@ -39,0 +39,0 @@ version: string; |
@@ -105,3 +105,3 @@ "use strict"; | ||
for (var i = 0; i < n.length; ++i) { | ||
var nn = (0, dom_1.xmlValue)(n[i]) - 0; | ||
var nn = parseInt((0, dom_1.xmlValue)(n[i])) - 0; | ||
if (cmp(s, nn)) { | ||
@@ -118,3 +118,3 @@ ret = true; | ||
for (var i = 0; i < n.length; ++i) { | ||
var nn = (0, dom_1.xmlValue)(n[i]) - 0; | ||
var nn = parseInt((0, dom_1.xmlValue)(n[i])) - 0; | ||
if (cmp(nn, s)) { | ||
@@ -121,0 +121,0 @@ ret = true; |
@@ -417,3 +417,3 @@ "use strict"; | ||
for (var i = 0; i < n.length; ++i) { | ||
sum += (0, dom_1.xmlValue)(n[i]) - 0; | ||
sum += parseInt((0, dom_1.xmlValue)(n[i])) - 0; | ||
} | ||
@@ -420,0 +420,0 @@ return new values_1.NumberValue(sum); |
@@ -7,3 +7,3 @@ import { XNode } from "../../dom"; | ||
constructor(value: any); | ||
stringValue(): any; | ||
stringValue(): string; | ||
booleanValue(): boolean; | ||
@@ -10,0 +10,0 @@ numberValue(): number; |
@@ -20,3 +20,3 @@ "use strict"; | ||
NodeSetValue.prototype.numberValue = function () { | ||
return this.stringValue() - 0; | ||
return parseInt(this.stringValue()) - 0; | ||
}; | ||
@@ -23,0 +23,0 @@ NodeSetValue.prototype.nodeSetValue = function () { |
@@ -36,3 +36,3 @@ import { XDocument, XNode } from '../dom'; | ||
outputDocument: XDocument; | ||
outputMethod: string; | ||
outputMethod: 'xml' | 'html' | 'text' | 'name'; | ||
outputOmitXmlDeclaration: string; | ||
@@ -39,0 +39,0 @@ version: string; |
@@ -91,3 +91,4 @@ "use strict"; | ||
escape: this.options.escape, | ||
selfClosingTags: this.options.selfClosingTags | ||
selfClosingTags: this.options.selfClosingTags, | ||
outputMethod: this.outputMethod | ||
}); | ||
@@ -94,0 +95,0 @@ return transformedOutputXml; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is too big to display
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
974643
245
9001
194