针对最近有关浏览器中 XSLT 支持的讨论,Jake Archibald 分享了一个对我来说很新颖的替代技巧,使 XML 文档在浏览器中可读:在 XML 顶部附近添加以下元素:
<script xmlns="http://www.w3.org/1999/xhtml" src="script.js" defer="" />
那<script xmlns="http://www.w3.org/1999/xhtml" src="script.js" defer="" />
然后,浏览器将执行script.js
,并可以通过使用正确的命名空间创建新元素来将 XML 替换为 HTML:
const htmlEl = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'html', ); document.documentElement.replaceWith(htmlEl); // Now populate the new DOM
标签:const htmlEl = document.createElementNS( 'http://www.w3.org/1999/xhtml', 'html', ); document.documentElement.replaceWith(htmlEl); // Now populate the new DOM
浏览器、 javascript 、 rss 、 xml 、 xslt 、 jake-archibald
原文: https://simonwillison.net/2025/Sep/2/making-xml-human-readable-without-xslt/#atom-everything