Readit News logoReadit News
Posted by u/vgr-land 7 months ago
Show HN: I Built a XSLT Blog Frameworkvgr.land/content/posts/20...
A few weeks ago a friend sent me grug-brain XSLT (1) which inspired me to redo my personal blog in XSLT.

Rather than just build my own blog on it, I wrote it up for others to use and I've published it on GitHub https://github.com/vgr-land/vgr-xslt-blog-framework (2)

Since others have XSLT on the mind, now seems just as good of a time as any to share it with the world. Evidlo@ did a fine job explaining the "how" xslt works (3)

The short version on how to publish using this framework is:

1. Create a new post in HTML wrapped in the XML headers and footers the framework expects.

2. Tag the post so that its unique and the framework can find it on build

3. Add the post to the posts.xml file

And that's it. No build system to update menus, no RSS file to update (posts.xml is the rss file). As a reusable framework, there are likely bugs lurking in CSS, but otherwise I'm finding it perfectly usable for my needs.

Finally, it'd be a shame if XSLT is removed from the HTML spec (4), I've found it quite eloquent in its simplicity.

(1) https://news.ycombinator.com/item?id=44393817

(2) https://github.com/vgr-land/vgr-xslt-blog-framework

(3) https://news.ycombinator.com/item?id=44988271

(4) https://news.ycombinator.com/item?id=44952185

(Aside - First time caller long time listener to hn, thanks!)

stmw · 7 months ago
It's nice to see this. Things used to be simple! (XSLT itself should've been simpler of course).

BTW, as I commented on earlier HN threads re: removal of XSLT support from HTML spec and browswers, IBM owns a high-performance XSLT implementation that they may want to consider contributing to one or more browsers. (It is a JIT that generates machine code directly from XSLT and several other data transformation and policy languages, and then executes it).

mananaysiempre · 7 months ago
> XSLT itself should've been simpler of course

I don’t think XSLT 1.0 is all that complicated. It’s a declarative language for transforming trees into trees or strings in an arbitrary manner, and you could argue that problem statement is too wide, but if you’re OK with it then I don’t think there’s any inappropriate complexity in the solution.

The surface syntax is bad, true, but that’s because of its verbosity, not its complexity. Once you put a bit of an Algol veneer on it[1], it becomes perfectly palatable.

[1] https://juniper.github.io/libslax/slax-manual.html

bawolff · 7 months ago
I think it would be very unlikely browsers would use a jit engine for xslt. They are removing it because they are afraid of the security footprint. A JIT engine would make that footprint much worse.
dpassens · 7 months ago
Not necessarily. The security issues are with the libxml implementation, a different one might be more secure even with JIT. That's part of what makes the whole situation so ridiculous.
stmw · 7 months ago
I don't think that follows, esp. since when we're talking about a mature, actively commercially maintained JIT engine.
chrismorgan · 7 months ago
One recommendation I’d make: replace RSS with Atom. Outside of podcasting, everything that supports RSS supports Atom, and Atom is just better, in various ways that actually matter for content correctness, and in this case in ways that make it easier to process. One of the ways that matters here: Atom <published> uses RFC 3339 date-time, rather than the mess that is RSS’s pubDate. As it stands, you’re generating an invalid JSON-LD datePublished. (If you then want to convert it into a format like “25 August 2025”, you’ll have to get much fancier with substringing and choosing, but it’s possible.)

One of the nice things about Atom is that you can declare whether text constructs (e.g. title, content) are text (good if there’s to be no markup), HTML encoded as text (easiest for most blog pipelines), or HTML as XML (ideal for XSLT pipelines).

cxr · 7 months ago
> Outside of podcasting, everything that supports RSS supports Atom, and Atom is just better

Is there something (besides (lack of) client support) that makes RSS better suited for podcasting?

chrismorgan · 6 months ago
Absolutely nothing. Technically, it’s strictly worse. People even added other namespaces to patch up some of its deficiencies, e.g. <content:encoded>.

I think the reason that RSS is used can be summed up as: Apple is lousy at developer relations.

They didn’t invent podcasting (name or technology), but they were the first major player to do stuff with it. Although consensus was already strong that RSS was technically terrible and Atom had existed for over a year (though it was not finalised) and was even fairly popular, Google especially having embraced it⸻ Apple chose the old-and-inferior RSS as their foundation. And then stuck their heads in the sand and didn’t talk to anyone, ever. Because that’s Apple’s style: throw stuff out there, let people do what they want with it, don’t attempt to be a community leader.

So what did everyone else do? Feeds had to be RSS, of course, to appease Apple. And then other apps implemented RSS, just RSS, like Apple had done, because what’s even the point of using Atom if it won’t work on the biggest platform? General-purpose feed readers didn’t have much specialised functionality, and had a few major players and a long tail of other clients; it was a much more well-distributed field, all things considered. But podcasting was, as I understand it, much more only one player for a while, then only up to two or three; and it depended on more specialised functionality. So it was never as democratic as general web feeds.

Over time podcast feeds ended up a horrible mess of repeating the same logical field 3–6 times in differently-named elements for different platforms, as they all added their own namespaces and mostly-identical-but-sometimes-slightly-different data fields¹. Because people were using it as an actual data format with domain-specific fields, they were more likely to just use an XML parser and talk just RSS, rather than a feed library which would be RSS-/Atom-neutral.

I believe that at some point Apple did implement Atom (not sure when), but it was too late, too much other stuff didn’t support it and so no one used it and so they ripped it out again a couple of years ago, and podcasting is set in stone using the inferior RSS.

I should write this up further at some point: the tragedy of podcast feeds.

—⁂—

¹ This stupid pattern can be seen on the web too. <meta name=description>, <meta property=og:description>, <meta name=twitter:description>, something in a JSON+LD block…

vgr-land · 7 months ago
Thanks for the suggestion I’ll dig into this, admittedly I haven’t worked with Atom so I didn’t consider it

A quick glance at Atom though says to me its worth an attempt to refactor.

chrismorgan · 7 months ago
For your possible interest, my own https://chrismorgan.info/atom.xsl is the most thorough Atom Feed Document stylesheet that I know of.

(I did also make an RSS version of it, https://temp.chrismorgan.info/2022-05-10-rss.xsl, including handling RSS’s stupid date format as perfectly as possible for some reason. It would actually be a useful guide for reversing that process, too…)

For maximum enthusiasm in this direction, make posts actual Atom Entry Documents. Will it benefit anyone? … well, I suppose it could be convenient for tooling to make a feed by just concatenating documents.

ajxs · 7 months ago
The core concept behind XSLT is evergreen: Being able to programmatically transform the results of a HTTP request into a document with native tools is still useful. I don't foresee any equivalent native framework for styling JSON ever coming into being though.
_heimdall · 7 months ago
If I'm not mistaken, XSLT 3 works with JSON too. It'd be nice to see that shipped in browsers instead of seeing v1 removed.
stmw · 7 months ago
I could easily imagine a functional-programming JSON transformation language, or perhaps even a JSLT based on latest XSLT spec. The key in these things is to constraing what is can do.
ajxs · 7 months ago
We wouldn't even need anything as complex as XSLT, or a functional language for transforming JSON. Other markup-based template processing systems exist for higher-level languages like Pug, Mustache, etc. for Node.js. You could achieve a lot with a template engine in the browser!
mpyne · 7 months ago
> I don't foresee any equivalent native framework for styling JSON ever coming into being though.

Well yeah I hope not! That's what a programming language is for, to turn data into documents.

asteroidburger · 7 months ago
XSLT 2.0 is Turing complete.
stuaxo · 7 months ago
Having something declarative is good here, and XSL fills that.
nashashmi · 7 months ago
Let’s rewrite W3C into XML and xslt.
nashashmi · 7 months ago
A few HN posts ago I commented this

> I want to see XSL import an XML. I want to see the reverse. XSL will be the view. XML will be the model. And the browser will be the controller. MVC paradigm.

It then dawned on me that the MVC framework for XML is where XML is the model (or data or database table). And XSLT is the viewer in the rear. Meaning the web browser can browse database information.

I never appreciated this very much before. The web has this incredible format to see database information in raw form or a styled form.

I still want to see development of it in reverse, and I hope to find better use cases now that I understand this paradigm.

supermatt · 7 months ago
It would not make sense to start from an XSLT. An XSLT is only a set of transformation rules (a transformation stylesheet). If there is nothing to transform, then the stylesheet produces nothing.

But you can kind of achieve what you want by treating the initial XML as a "view definition/configuration", and the referenced XSLT as a "view builder", and referencing your "model" as an external document via XPath document and applying to the XSLT template(s). i.e. you create configurations of your view that apply external data.

dehrmann · 7 months ago
Haven't seen this much interest in XML/XSLT in 20 years.
wiz21c · 7 months ago
Fortunately! It was cool to do the easy things, but then you had monstruous path expressions, and all sort of programmatical drama.. Pfff...

did you know that XSLT was shown to be Turing complete ? https://staff.emu.edu.tr/zekibayram/Documents/papers/XSLT_Tu...

On the other side, I find XML/XSD still much better than JSON. JSON is way too simple...

whizzter · 7 months ago
Depends on the task, JSON won because it was so simple whilst XML is waaay to complex. Maybe an alternative to JSON with just a tad more complexity for sanity could have won 20 years ago, but alas it never happened.
MrGilbert · 7 months ago
Nice one! Although it seems that the engineers at the different browser vendors are committed to remove XSLT due to reasons outlined here [1]. It's a shame these Discussions got so heated, but that's just the nature of the internet, I guess.

[1]: https://github.com/whatwg/html/issues/11523#issuecomment-318...

//Edit: Rephrased "PRs" to "Discussions".

afavour · 7 months ago
Unfortunately a topic like this is perfect bait for a lot of the resentments folks have with the modern internet ecosystem.

There’s some rarely used tech that few have talked about in a long time. Tech giants have decided somewhat unilaterally to get rid of it because it’s barely used and has had security flaws.

There’s a discussion to be had about that specifically but most people didn’t care a jot about XSLT until it was threatened. What they do care about is tech giants controlling the fate of the internet. That’s a far bigger issue than can be solved in a GitHub discussion, but it doesn’t stop anyone trying.

_heimdall · 7 months ago
There is a related issue to instead add XSLT 3 support [1]

[1] https://github.com/whatwg/html/issues/11578

ulrischa · 7 months ago
I wonder why everybody want's to use XSLT on the client side. On te Server side it is so powerful and works like a charme with PHP: // XML $xml_doc = new DOMDocument(); $xml_doc->load("file1.xml");

// XSL $xsl_doc = new DOMDocument(); $xsl_doc->load("file.xsl");

// Proc $proc = new XSLTProcessor(); $proc->importStylesheet($xsl_doc); $newdom = $proc->transformToDoc($xml_doc);

// Output print $newdom->saveXML();

vbezhenar · 7 months ago
> I wonder why everybody want's to use XSLT on the client side

Because if you can remove any server processing, it's just the perfect solution for simple websites.

theknarf · 7 months ago
Suggestion, replace this:

    <item>
      <title>Last Blog Post</title>
      <description>
        I am Jack's XML Parser. I consume unclosed tags I kill jack.
      </description>
      <link>https://xsltblogdemo.vgr.land/content/posts/20250707.xml</link>
      <guid isPermaLink="false">post-20250707</guid>
      <pubDate>Mon, 7 Jul 2025 13:00:00 +0000</pubDate>
      <author>vgr.xsltbf@example.com (vgr)</author>
    </item>
With this:

    <post
      title="Last Blog Post"
      description="I am Jack's XML Parser. I consume unclosed tags I kill jack."
      link="https://xsltblogdemo.vgr.land/content/posts/20250707.xml"
      isPermaLink="false"
      guid="post-20250707"
      pubDate="Mon, 7 Jul 2025 13:00:00 +0000"
      author="vgr.xsltbf@example.com (vgr)">
    Content of the post....
    </post>

IshKebab · 7 months ago
Perfectly illustrating one of XML's stupidest flaws.
jprjr_ · 7 months ago
I don't know if this is intentionally hilarious or unintentionally hilarious, I guess it's the same result either way.

Dead Comment