3 ms·
XSLT did have some nice bits - I still like XPath. Edit: Just to be clear some of the most terrifying code I've ever seen (and possibly wrote) was in XSLT.
by arethuza 10y ago
XSLT did have some nice bits - I still like XPath.
Edit: Just to be clear some of the most terrifying code I've ever seen (and possibly wrote) was in XSLT.
- cowardlydragon 10y agoBut but but it's FUNCTIONAL, and turing-complete!!! // yes I understand the use cases of functional code
- DonHopkins 10y agoDSSSL [1], the SGML predecessor of XSLT and CSS, included a full blown built in Scheme interpreter, by the standard. That turned out to be a bit too much raw power and complexity for most people, so it never really caught on outside of the Boeing Airplane Maintenance Manual Publication Department and other big enterprisy SGML-loving organizations like that. Microsoft's non-standard implementation of XSLT [2] is "out of the tarpit" Turing complete [3] because it lets you write handlers in JavaScript and other languages, to actually get some useful work done and call external librarys, without bending over backwards. Of course Microsoft's non-standard extensions to XSLT aren't supported outside of Windows. But after using it, going back to plain XSLT was pretty frustrating to me, and in many cases it was easier just to forget about XSLT and write straight-up JavaScript code with XML parsing and XPath expressions. There's nothing that XSLT can do that you can't easily implement in a JavaScript library. At this point it's better to start with JavaScript and forget about XSLT, instead trying to use XSLT, hitting a wall, realizing you want to ship on some platform other than Windows, then rewriting it all in Java, then realizing you want it to run in the browser, then rewriting it all in JavaScript, which you should have started with in the first place. Another point for JavaScript: In the past decade, a whole hell of a lot more effort has been put into making JavaScript run fast, than making XSLT run fast. [1] https://en.wikipedia.org/wiki/Document_Style_Semantics_and_Specification_Language https://en.wikipedia.org/wiki/Document_Style_Semantics_and_S... [2] https://msdn.microsoft.com/en-us/library/bb986124.aspx https://msdn.microsoft.com/en-us/library/bb986124.aspx [3] https://en.wikipedia.org/wiki/Turing_tarpit https://en.wikipedia.org/wiki/Turing_tarpit
- benibela 10y agoIsn't standard XSLT Turing complete anyways? Even XPath 3 is Turing complete
- DonHopkins 10y agoThe point is that XSLT is deeply stuck in the "Turing Tarpet": "Beware of the Turing tar-pit in which everything is possible but nothing of interest is easy." -Alan Perlis https://en.wikipedia.org/wiki/Turing_tarpit https://en.wikipedia.org/wiki/Turing_tarpit You would never want to write a JPEG decoder in XSLT, but the fact that it might be possible if you were willing to bend over backwards, write unmaintainable code that runs incredibly slowly and requires colossal amounts of memory, misses the point. For getting real work done in the real world, where big companies have mountains of data to process, and are required to pay real money for electrical power and computing equipment, Microsoft decided to add the ability to call JavaScript, Visual Basic, and other scripts from XSLT templates. Because it's just too hard to get anything of interest done in XSLT, and it's trivial and convenient in JavaScript, and there's probably already a library to do it.
- benibela 10y agoBut it is not deeply in the tar-pit. Here is an raytracer written in XQuery: https://dev.w3.org/cvsweb/2011/QT3-test-suite/app/Demos/raytracer.xq?rev=1.2;content-type=text%2Fplain https://dev.w3.org/cvsweb/2011/QT3-test-suite/app/Demos/rayt... (imported modules are in the directory above) looks quite maintainable to me. XQuery is pretty much XPath-with-functions, and XPath 3 has anonymous functions, so you can directly translate it to XPath 3 by replacing `declare function foo(..` with `let $foo := function(...` Once it is XPath, you can put everything in a xsl:value-of tag.
- DonHopkins 10y agoI'd prefer to be on a mountain top far away from any tarpit, than only partially submerged in a tarpit. The mountain tops are modern JavaScript engines. How much work have Mozilla, Google, Apple, IBM and many other big organizations and excellent engineers poured into making XSLT run fast and efficiently in the last decade, compared to how much has been applied to JavaScript? Can you cite any interesting SIGPLAN articles about XSLT optimization? Have any commercial games shipped using a ray tracer implemented in XSLT?
- manarth 10y agoIncrease the terror further by adding Jsonx to the mix: http://www.ibm.com/support/knowledgecenter/SS9H2Y_7.5.0/com.ibm.dp.doc/json_jsonx.html http://www.ibm.com/support/knowledgecenter/SS9H2Y_7.5.0/com....
- arethuza 10y agoIsn't one of their examples invalid XML? http://www.ibm.com/support/knowledgecenter/SS9H2Y_7.5.0/com.ibm.dp.doc/json_jsonxconversionexample.html http://www.ibm.com/support/knowledgecenter/SS9H2Y_7.5.0/com.... Shouldn't <json:string name="ficoScore"> > 640</json:string> be <json:string name="ficoScore"> > 640</json:string>
- manarth 10y agoIt's one of the many peculiarities of XML: the "less-than" bracket is not allowed in text (because it could indicate the opening of a new XML tag), but the "greater-than" bracket does not need encoding when it's in text, because it's not ambiguous.
- arethuza 10y agoI'm pretty sure most XML handling libraries would use > - never seen a raw > used in XML (though possible I might not have noticed). Edit: Forgot to say thanks for pointing that out!
- benibela 10y agoJust check what the W3C says about writing a raw >: > For characters such as > where XML defines a built-in entity but does not require its use in all circumstances, it is implementation-dependent whether the character is escaped. (https://www.w3.org/TR/xslt-xquery-serialization-31/#serphases https://www.w3.org/TR/xslt-xquery-serialization-31/#serphase...)
- benibela 10y agoIf you like XPath and JSON, too, you can use my just updated Xidel (http://www.videlibri.de/xidel.html http://www.videlibri.de/xidel.html) to run XPath queries on JSON. It can do transformations, where you write the output structure, and then pick the values from the input JSON. E.g. to transform from {"a": [{"b": 123}, {"b": 456}]} to {"c": [123,456]}, you could write an XPath expression {"c": a/b }