Ask HN: Have you built a website in XML and XSLT?

7 points by rsolva ↗ HN
I have read up a bit on XML + XSLT the last few days, knowing very little about it, and was surprised to learn that it is rendered entirely in the browser without the need for server side processing or JavaScript.

If any of you have made a website using only XML + XSLT – how did you structure the content and what strategies did you use to write and include repeating elements (like header, footer etc)?

Feel free to leave real world examples or write-ups in the comments!

18 comments

[ 3.4 ms ] story [ 57.3 ms ] thread
This is a very old way of building websites. I have not heard of this being done in a very long time. The problem was maintainability of the XSLT sheets. And although you say no server-side processing is needed, the XML was almost always generated server-side from underlying database queries. That’s the only way to make the pages dynamic.
Yeah, it seems like it went out of use between 2010-16, altough XSLT v3 was "released" in 2017.

My main interest is to find out if XML/XSLT can be used to write reusable components, like a header and footer, that can be easily included on every page on a static site.

Yes, easily.
Then the question becomes; how? From what I can see, the standard way is to push data, no pull. Data is stored in the XML-file and a stylesheet is called upon to manipulate that data.

What if I wanted to make a classic blog structure with posts in a /content folder, fetch (pull) the title and description from each post and display it on the front page?

You fetch XML, JSON, or structured plaintext documents from the content folder, use XPath (XML or JSON) or use string processing (plaintext) to retrieve the appropriate fields, and transform the data to HTML. Short of writing your application for you, I don’t see how you expect an answer other than “it can be done.” You need to learn how to use the toolset, as with any other language.
One key point is that the XML do not need to be stored as files on the server. They can be generated at request time by turning database queries into XML responses using your favorite server-side language. The XSLT can be hosted as static files on the webserver.
I’ve personally used AsciidoctorJS + SaxonJS to render pages. I keep intending to see what I can do with the HN API and XPath/XSLT.
Why would you bother doing that in 2022? It doesn’t really seem relevant anymore.
Why on earth wouldn’t I? I wanted to experiment, learn a few things, have a bit of fun. Not everything needs to be super serious.
I did not realize you’re doing it for experimentation. I thought some kind of live product.
XSLT was a fad for a couple years in the late 90's through early 2000's. I briefly worked at a company that used XSLT as part of a content management system. It wasn't good then, and I wouldn't touch it with a ten foot pole now.
I have read many comments here on HN that suggests that many have had a love/hate relationship with XML/XSLT.

I currently use Hugo as my go-to static site generator for smaller projects, but started pondering if it would be possible to skip the compilation step entirely by using XML/XSLT.

XML and XSLT are still very much in use, especially in Europe and industries where data schematization & long-term retention are important. I’ve written XSLT applications for use in banking, healthcare, technical publishing, and compliance markets.

For you, I recommend checking out the Docbook transformations and Saxon-JS. The former is a tool for publishing technical documentation to HTML, the latter is an compliant XSLT processor implemented in the browser/NodeJS.

XSLT/XQuery/XPath are excellent tools for querying and restructuring tree-structured data. There are a lot of people out there who have very little experience but great big opinions: you should ignore them.

Note that these technologies are functional programming languages. It will likely take some effort to wrap your head around it all. Michael Kay’s book is a good start, but unfortunately is not updated for the v3 spec.

You can skip the XSLT part and use CSS and XML together.
Nice to know, although I think I need the functionality XSLT offers to further manipulate / select data from the XML.
I didn't build it myself, but I maintained one for a while as part of a student job.

The website itself was hosting various resources for researchers, etc. Each resource was annotated via a specific XML format and XSLT was used to dynamically create HTML pages, as well as to transform the XML files into various other file formats.

The by far biggest problem was, and still is, that XSLT is very verbose and not well-maintainable. Small changes here and there were possible, but larger changes almost always required rewriting the entire stylesheet. On top of that, the XML format got bigger and bigger as well (as it was used and modified by Universities across Europe), edge cases were added, etc., that did not help when it came to writing the XSLT stylesheets, but that's a different problem. We also had to switch to XSLT 3.0 at some point and had to render the HTML server-side, since browsers don't support anything beyond XSLT 1.0.

Overall, I still kind of enjoyed working with it. For complex XML, it was by far the easiest way to work with them.

I was as well surprised when I found the NGINX website code was and still is implemented in XML + XSLT and XSLS! Have a look for yourself: http://hg.nginx.org/nginx.org/file/tip
Wow, thank you, this was exactly what I need! I have struggled to find an example of a site that is in production and has published the source.

Looking through the (very few) tutorials on this topic is a slow way to get the gist of how XML + XSLT could be implemented and the official W3C specs are really dry and dense.