4 ms·
I don't think, in 20 years with HTML, that I've used string interpolation. Why would you when there's a web standard (XSLT) that gives you declarative templates
by intrasight 3y ago
I don't think, in 20 years with HTML, that I've used string interpolation. Why would you when there's a web standard (XSLT) that gives you declarative templates? In my more recent work, I've used LINQ to XML "templates" for this. It's functional vs declarative. The approach works with JSON or XML input. And seeing how Microsoft isn't invested in XSLT, it'll be my approach moving forward.
https://learn.microsoft.com/en-us/dotnet/standard/linq/functional-transformation-xml https://learn.microsoft.com/en-us/dotnet/standard/linq/funct...
- binarymax 3y agoI don't think, in 30 years with HTML, that I've come across a library or technique that I prefer over string templates. They're so easy. And especially since ES6 has `format ${my_variable}` interpolation, it's even easier!
- psychoslave 3y agoWith ES6 there is actually even more: tagFunction`string text ${expression} string text` https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates https://developer.mozilla.org/en-US/docs/Web/JavaScript/Refe...
- pmontra 3y agoThere has been a short moment in the history of the web when XML + XSLT looked like to become the way to go. It was at the end of the 90s, when we were looking at a way to develop web sites for both people at home with modems or slow fiber and for people with 2G phones (that is even slower modems and very small screens). We had HTML and WAP and products to apply XSLT to XML and deliver the same site to both audiences. Then 3G came with larger screens, faster CPUs, better browsers and in a few years we were using HTML for everybody with responsive layouts, media query, etc to the rescue. This is probably the first time I heard about XSLT in the last 10 years.
- jgalt212 3y agoDon't the people who read your code get angry that you used XSLT?
- intrasight 3y agoConfused at first and then astounded perhaps that there's a standard declarative approach. But never angry. And they get paid to read my code, so if they have any such emotion, they know that they best keep it to themselves. Also, non-programmers dig XSLT specifically because it's not "code".
- jgalt212 3y agoto each his own, I guess.
- 0x4f78 3y agoIt definitely feels "unnatural" that others don't get angry.
- Devasta 3y agoYes they do! I manage a team of reporting analysts who have to maintain data feeds from our clients to brokers. They are from business and accounting backgrounds and use XSLT for it all. They don't need to worry about build steps or any of that junk, we just store the transforms in a database and they use IntelliJ to incrementally build out the files to the brokers specs, and we can display the transforms in a UI to other staff so they can know whats going on whenever there are questions. Hundreds of reports, couldn't manage it all without XSLT.
- regularfry 3y agoI think Martin Fowler's on record... somewhere... saying that his sites are that sort of thing. XML, XSLT, and a Makefile.
- schemescape 3y agoXSLT has a steep learning curve and it’s extremely verbose. But my main problem with it is that (as far as I know) XHTML isn’t being updated alongside the current HTML spec (with semantic elements). Related: I’ll admit that I used to use XSLT for my static site generators [1] and now I’ve switched to string interpolation (with conservative escaping as the default) [2]. Edit: In my case, the goal was to simplify and reduce dependencies. [1] https://github.com/jaredkrinke/flog/blob/main/post.xsl https://github.com/jaredkrinke/flog/blob/main/post.xsl [2] https://github.com/jaredkrinke/literal-html https://github.com/jaredkrinke/literal-html
- epilys 3y agoVery cool use of XSLT is rendering an RSS feed as html if viewed from a browser. So if someone clicks on your feed icon, they don't get an .XML download but a webpage instead: https://pitsidianak.is/blog/feed.xml https://pitsidianak.is/blog/feed.xml NoScript on firefox is blocking it for me, but there's no javascript involved, only XSLT, HTML and CSS.