Hacker Newsnew | past | comments | ask | show | jobs | submit | qaribou's commentslogin

We were probably using it for very different things (I used it to render my HTML for a PHP site), but I actually found the debugging part to be a huge advantage of xslt. The errors I had relating to basic config and encoding issues were all big headaches, sure, but debugging issues caused by my own incorrect assumptions about how my data was structured was great -- I never felt lost and every message gave me a clear idea what I needed to look at.


Learning XSLT definitely helped me write much better views in any MVC/MVVM project I have, because the whole approach to template matching is useful as a general design principle. When I'd first started in web development, my views were all very top-down and rife with control logic. After spending considerable time rendering my pages by building XML and applying XSLT, I found a lot of the skills transfer.

Lately I've been working a lot in React, and I've found that just understanding the new syntax can be learned in a weekend -- instead of transforming an XML doc, I load JSON into my state, and instead of writing <xsl:template>s I write React classes. The sort of skills that one refines over years, namely how to think of your rendered page as being composed of various smaller templates, benefit me everywhere. XSLT was a really intensive way to force myself to learn to think that way. Even my mixed PHP/HTML that I occasionally still have to write is considerably better.

to your point about XSLT v1, I can speak to why it's so rarely used at least by PHP devs: v1 has been included as a default extension in PHP builds for many years, but v2 has always required a separate installation of saxon. I just checked on my reasonably up-to-date ubuntu default install, and it's XSLT 1.1.28. That's still far better than Go, where the only approach I've seen is to just install command-line xsltproc and execute that. v2.0 isn't going to catch on while v1.0 is what's considered the de-facto standard, and v1 being the de-facto standard is a big part of why so many have a poor opinion of xslt.


I'd recently experimented with XSLT for a PHP site's templating engine, after having ignored it since learning it about a decade ago. I swapped out all PHP code to load a bunch of variables for building a big DOMDocument tree in-memory, then applying my XSLT to that to build the rendered HTML. Once I stopped trying to stick a bunch of <xsl:if> and <xsl:for-each>es all over the place, and took a compositional approach to templating where I simply defined the <xsl:template>s I needed and then put <xsl:apply-templates> where I wanted them to go, it actually worked extremely well. All my templates were nicely organized, and I'm far happier working in XML than HTML, with all it's wacky requirements with some tags needing to be closed and others not. It's just the little things that really made me happy -- sticking my fontawesome icons in with an <i class="fa fa-pied-piper" /> instead of <i class="fa fa-pied-piper"></i> always brought a smile to my face. It also made testing nice and fast since it's pretty easy to save the XML I want to transform as a file outside of my PHP app, and just xsltproc it from a terminal until I get it working how I want it.

The big pain points were all around the library support. The XSLT lib was generally fine, but the XML processing PHP provides was rubbish. The main complaint I heard was that even PHP5.5 wouldn't support outputting as html5, and you need to manually just echo out a '<!DOCTYPE html>' to work around that. I couldn't just import HTML directly from elsewhere as rendered by my CMS into my document tree either - it needed to have string literals of tags concatenated to it just to work. The sheer number of piddly little flags that are barely documented but you need to get exactly right in order for it to work at all was a big nuisance too. I also needed to turn off all parser warnings so it wouldn't barf on reading html5 docs, and when a big advantage of the language is that you can be strict about your markup, it seems quite silly to have to turn off warnings.

Looking back on it, none of my problems were really with XSLT as a language, just with how it's implemented in various languages. I feel like a lot of people got turned off when they learned about it in school, and consequently nobody was interested in doing a good job of implementing its supporting libraries in any language.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: