Making XML human-readable without XSLT

AI-generated summary of reporting by Simon Willison’s Weblog. Read the original for the full story.

Why it matters

Gives RSS/XML publishers a browser-native way to render XML as HTML now that XSLT support is being questioned, though it hinges on continued script execution in XML documents.

Read this as

A blog post by Jake Archibald describes a trick for making raw XML files, like website feeds, readable in a browser without using XSLT, the old styling language browsers may be dropping. You add a single script tag inside the XML file pointing to a JavaScript file. That script replaces the XML page with a normal HTML page the browser can display nicely. It mainly affects people who publish XML feeds such as RSS and want them readable when clicked.

Amid debate over browsers dropping XSLT, a decades-old technology for styling XML, Jake Archibald published a workaround for publishers of XML documents such as RSS feeds. It uses a script tag within the XML itself to run JavaScript that swaps in HTML. The cost is one extra script file per feed; the risk is that it depends on browsers continuing to run scripts in XML documents. Teams maintaining public XML feeds gain an alternative now, but it is not a standard.

Jake Archibald proposes adding an XHTML-namespaced <script src="script.js" defer/> element to an XML document. The browser executes that script, which calls document.createElementNS('http://www.w3.org/1999/xhtml', 'html') and uses document.documentElement.replaceWith() to substitute an HTML element, then populates the new DOM. This avoids XSLT entirely while remaining in-browser. Limitations: the XML must be allowed to load scripts, and no cross-browser testing data is given.

Read the original

This summary exists to save you time, not to replace the source.

Key terms

XSLT XML RSS JavaScript HTML

Was this summary useful?

One click, anonymous. It tells us which summaries to re-run.

Related reading