-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unifying attributes with other child nodes. (#84)
* Unifying attributes with the rest of child nodes. * Refactoring `Xslt` class. * Refactoring `xml-functions` and `xml-parser` to use child nodes as attributes. * `xmlValue` should not consider attributes. * Fixing unit tests that were using `attributes` property to assert results. * Getting rid of `transformedAttributes`. * The XML output should *not* consider attributes for determine whether tags should be self-closed or not. * - Improving types among different sources; - Fixing xPath expressions to not consider attributes for most of cases. * - Even more types; - Changing `xsltVariable` to not consider attributes while deciding how to set the `NodeValue` object. * Fixing typing for `PredicateExpr`.
- Loading branch information
1 parent
4b4afc5
commit b9b64d1
Showing
19 changed files
with
291 additions
and
188 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,7 @@ import { | |
XML11_VERSION_INFO | ||
} from './xmltoken'; | ||
import { XNode } from './xnode'; | ||
import { DOM_ATTRIBUTE_NODE } from '../constants'; | ||
|
||
/** | ||
* Original author: Steffen Meschkat <[email protected]> (the `xmlParse` function, | ||
|
@@ -67,12 +68,17 @@ export class XmlParser { | |
}; | ||
let n = node; | ||
while (n !== null) { | ||
for (let i = 0; i < n.attributes.length; i++) { | ||
if (n.attributes[i].nodeName.startsWith('xmlns:')) { | ||
const 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; | ||
for (let i = 0; i < n.childNodes.length; i++) { | ||
const childNode = n.childNodes[i]; | ||
if (childNode.nodeType !== DOM_ATTRIBUTE_NODE) { | ||
continue; | ||
} | ||
|
||
if (childNode.nodeName.startsWith('xmlns:')) { | ||
const prefix = childNode.nodeName.split(':')[1]; | ||
if (!(prefix in map)) map[prefix] = childNode.nodeValue; | ||
} else if (childNode.nodeName == 'xmlns') { | ||
if (!('' in map)) map[''] = childNode.nodeValue || null; | ||
} | ||
} | ||
n = n.parentNode; | ||
|
@@ -258,11 +264,15 @@ export class XmlParser { | |
} else { | ||
if ('' in namespaceMap) node.namespaceUri = namespaceMap['']; | ||
} | ||
for (let i = 0; i < node.attributes.length; ++i) { | ||
if (node.attributes[i].prefix !== null) { | ||
if (node.attributes[i].prefix in namespaceMap) { | ||
node.attributes[i].namespaceUri = namespaceMap[node.attributes[i].prefix]; | ||
} | ||
|
||
for (let i = 0; i < node.childNodes.length; ++i) { | ||
const childNode = node.childNodes[i]; | ||
if (childNode.nodeType !== DOM_ATTRIBUTE_NODE) { | ||
continue; | ||
} | ||
|
||
if (childNode.prefix !== null && childNode.prefix in namespaceMap) { | ||
childNode.namespaceUri = namespaceMap[childNode.prefix]; | ||
// else, prefix undefined. | ||
} | ||
// elements with no prefix always have no namespace, so do nothing here. | ||
|
Oops, something went wrong.