Ask HN: Have you built a website in XML and XSLT?
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 ] threadMy 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.
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?
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.
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.
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.
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.