Skip to content

Commit e5a68f1

Browse files
Nodes should be sorted as the input order for the output.
1 parent 6b90aef commit e5a68f1

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

src/dom/xml-functions.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,8 @@ function xmlElementLogicTrivial(node: XNode, buffer: string[], options: XmlOutpu
232232
}
233233
}
234234

235-
const childNodes = node.transformedChildNodes.length > 0 ? node.transformedChildNodes : node.childNodes;
235+
let childNodes = node.transformedChildNodes.length > 0 ? node.transformedChildNodes : node.childNodes;
236+
childNodes = childNodes.sort((a, b) => a.siblingPosition - b.siblingPosition);
236237
if (childNodes.length === 0) {
237238
if (options.selfClosingTags) {
238239
buffer.push('/>');
@@ -257,7 +258,8 @@ function xmlElementLogicTrivial(node: XNode, buffer: string[], options: XmlOutpu
257258
* @param cdata If using CDATA configuration.
258259
*/
259260
function xmlElementLogicMuted(node: XNode, buffer: any[], options: XmlOutputOptions) {
260-
const childNodes = node.transformedChildNodes.length > 0 ? node.transformedChildNodes : node.childNodes;
261+
let childNodes = node.transformedChildNodes.length > 0 ? node.transformedChildNodes : node.childNodes;
262+
childNodes = childNodes.sort((a, b) => a.siblingPosition - b.siblingPosition);
261263
for (let i = 0; i < childNodes.length; ++i) {
262264
xmlTransformedTextRecursive(childNodes[i], buffer, options);
263265
}

0 commit comments

Comments
 (0)