
Standard Web Templates (A Proposal)
Template processing is something nearly every website has to do, and it's frankly baffling that there is no standard way to do it. Oh wait, there is. It's called XSLT, and the consortium of Web browsers has coordinated …
以下正文同步自 Hacker News 最新,版权归原站所有,已转换为易读排版。
Template processing is something nearly every website has to do, and it's frankly baffling that there is no standard way to do it. Oh wait, there is. It's called XSLT, and the consortium of Web browsers has coordinated to eliminate it.
XSLT got many things right that so-called "modern" client-side Web templating systems still fail to accomplish:
However, XSLT is not without its shortcomings:
Yes, it's old, but it's only old in Web browsers. XSLT is actually still used extensively in publishing, and has been updated several times since it was first released in 1999. In fact, a draft of version 4.0 shipped the same week as that GitHub issue moving to nuke XSLT from the Web was posted.
Yes, the functionality of XSLT 1.0 sucks. That was pretty much all fixed in XSLT 2.0. In 2007. Did the browsers update their implementations? No they did not. In fact the WebKit team blamed the maintainer of the (open-source) LibXSLT for not doing it. For free. (This does not excuse Mozilla, as they have their own implementation.)
Yes, it only operates over XML, and XML is out of style. (Actually, XSLT 3.0 can process JSON.)
Yes, XPath is hard (I guess?? It's not much harder than CSS selectors). That point is conceded(ish).
Yes, the syntax absolutely is awful. It is a terrible experience to read and especially to write. That point is absolutely conceded.
I humbly submit that these are all tractable problems.
Then, it would simply be a matter of writing a little transpiler that transforms that syntax into the canonical XML one that nobody likes typing. There are already (at least) three implementations of XSLT 3.0 written in Rust which could be compiled to WASM. They're still young but a little elbow grease and some tokens could bring one or both of them up to conformance. Then it would be a matter of lobbying the W3C to adopt the hook and the HTML semantics profile, which could be the same specification, and either the W3C or WHATWG to adopt the syntax specification (or heck, just put it out as an IETF RFC).
Then, just like JSON, which got its own DOM implementation because people kept eval()ing it, we yell at the browsers to put XSLT back. Then we have a nice, clean, sensible, standard Web templating system forevermore.
Here is an idea for what SWeT could look like, which I apparently sketched out all the way back in 2019:
xslt compact syntax mockup number one
shell-style comments (of course)
turtle/sparql style namespace declarations
prefix html: http://www.w3.org/1999/xhtml
idea is we have an inventory of reserved words which if you need to
you can override with % just like haml. other than that the first
thing on the line is treated like an element name
abridged template syntax? name/mode, match, priority
template#name html:foo 100 {
params only appear at the beginning of a template, maybe this?
$$ { hurr: "durr" }
abridged command elements of course (this would be xsl:for-each)
each html:bar {
do we do it like haml? i'm not a fan of semantic indentation,
but something like this might be okay:
p all subsequent tokens become a text node; p next element on same line
p 'quotes optional; eg for if you want to include a literal semicolon'
i'm much more partial to something like this
p id: 'foo', class: $var { child element }
automatically determine between xsl:if and xsl:choose; xpath
functions pass through, of course
if position() mod 2 {
this could be a way to apply templates with a mode
apply#odd . } else { apply#even . param: 'val', other:param { something more elaborate } } } }
We Can Just Do Things
Love,
正文由 探How 从来源站点 RSS 同步,内容未经改写;遇到排版缺失或需要图片、视频时请以原文为准。