Skip to content

Commit 6868b09

Browse files
drottchromium-wpt-export-bot
authored andcommitted
Add a test for using DOMParser output with XSLTProcessor.
This test verifies that a Document parsed by DOMParser can be successfully imported into an XSLTProcessor and used to transform another Document, producing the expected HTML output. Needed in Blink to verify whether we can independently switch the XML parser for DOMParser while still process XSLT. Bug: 441911594, 466303347 Change-Id: Ie4b3bffa1d0f6ff799f29b36bedf2d56d33fca91 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/7254057 Auto-Submit: Dominik Röttsches <drott@chromium.org> Reviewed-by: Joey Arhar <jarhar@chromium.org> Commit-Queue: Joey Arhar <jarhar@chromium.org> Cr-Commit-Position: refs/heads/main@{#1558261}
1 parent 68fc239 commit 6868b09

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

dom/xslt/domparser-xslt.html

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<head>
4+
<title>DOMParser output as XSLT Stylesheet</title>
5+
<script src="/resources/testharness.js"></script>
6+
<script src="/resources/testharnessreport.js"></script>
7+
</head>
8+
<body>
9+
<div id="output-container"></div>
10+
11+
<script>
12+
test(() => {
13+
const xsltStr = `
14+
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
15+
<xsl:template match="/">
16+
<ul>
17+
<xsl:for-each select="data/item">
18+
<li><xsl:value-of select="name"/>: <xsl:value-of select="value"/></li>
19+
</xsl:for-each>
20+
</ul>
21+
</xsl:template>
22+
</xsl:stylesheet>`;
23+
24+
const xmlStr = `
25+
<data>
26+
<item><name>Alpha</name><value>10</value></item>
27+
<item><name>Beta</name><value>20</value></item>
28+
</data>`;
29+
30+
const parser = new DOMParser();
31+
const processor = new XSLTProcessor();
32+
33+
const xsltDoc = parser.parseFromString(xsltStr, "text/xml");
34+
const xmlDoc = parser.parseFromString(xmlStr, "text/xml");
35+
36+
processor.importStylesheet(xsltDoc);
37+
const fragment = processor.transformToFragment(xmlDoc, document);
38+
39+
const container = document.getElementById("output-container");
40+
container.appendChild(fragment);
41+
42+
const listItems = container.querySelectorAll("li");
43+
assert_equals(listItems.length, 2, "Should have exactly 2 list items");
44+
assert_equals(listItems[0].textContent, "Alpha: 10", "First item content mismatch");
45+
assert_equals(listItems[1].textContent, "Beta: 20", "Second item content mismatch");
46+
47+
}, "Verify XSLT transformation from DOMParser creates expected HTML output.");
48+
</script>
49+
</body>
50+
</html>

0 commit comments

Comments
 (0)