cousin_it
13 hours ago
When I first learned that XSLT was going away, I got curious how to achieve the same thing in JS (client-side templating that happens during page load, without any "flash of content"). It turns out there's a very nice way to do it, by using inline scripts that append elements next to document.currentScript. Lean Rada wrote about it here: https://leanrada.com/notes/inline-rendering-currentscript/ and I wrote about it as well: https://vladimirslepnev.me/write
dfabulich
6 hours ago
You can also style XML documents with CSS, like this:
<link rel="stylesheet"
href="style.css"
xmlns="http://www.w3.org/1999/xhtml" />WCSTombs
13 hours ago
That Lean Rada article is really fun!
russellbeattie
10 hours ago
Instead of:
<script>document.currentScript.replaceWith(new Date().getFullYear())</script>
How about: <svg onload="this.outerHTML=new Date().getFullYear()"/>
Not as pretty, and you'd have to escape all the quotes, but still pretty usable.panzi
7 hours ago
Hm, does document.write("...") still exist?
esprehn
10 hours ago
That won't work with trusted types enabled.
russellbeattie
8 hours ago
Well this works too:
<svg onload="this.replaceWith(new Date().getFullYear())"/>