I only wonder, where is XSLT usually used? Can anyone outline the most typical types of projects and environments?
I only wonder, where is XSLT usually used? Can anyone outline the most typical types of projects and environments?
XSLT is kind of 'declarative', but it has ifs, switches, ... They probably didn't start out with the plan to implement a programming language with xml tags, but they did. It's horrible.
Edit: XML Schema is horrible as well. This is how you define an element with string content, and one attribute (which is VERY basic):
<xs:element name="myElement">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute name="myAttribute" type="xs:string" />
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
Just off the top of my head, I could invent something better, like: <myElement myAttribute="xs:string">xs:string</myElement>XML Schema tries to validate both the tag hierarchy and the contents, which requires data types and complicated definitions. So much overkill...
DTD and XPath are actually very nice and simple. This is the DTD equivalent of my XML Schema example above:
<!ELEMENT myElement (#PCDATA)>
<!ATTLIST myElement myAttribute CDATA>
I could see myself writing a small domain language and translate it to DTD, to make it even nicer.Hand editing XML schema files is too much of a pain.
<xsl:if test="x">template</xsl:test>
is basically this in Lisp: (if eval(x) (apply-template template) nil)
And <xsl:for-each> is equivalent to map in Lisp. It's a functional projection, not an imperative loop, even if the syntax looks like that of an imperative language. <element name="myElement">
<attribute name="myAttribute">
<text/>
</attribute>
<text/>
</element>
OK, it's not great, but it's better.https://github.com/mikecardwell/email-privacy-tester/blob/ma...
The cool thing is, I initially wrote the application in Perl. I then re-wrote it in NodeJS, but was able to re-use the same stylesheet as it's language independent.
This sounds great in theory. But the problem is real world business requirements don't work that way. Real specs are never a straightforward declarative transformation. They always include bells and whistles and rhinestones that don't fit into XSLT. Loop over this set and suppress records where this field matches the previous record (state!), or include pagination, or call somebody's web service in the middle of it to display today's stock price, or grab the user's preferences for colors and time zones. (All real examples from a job I had with XSLT once upon a time.) XSLT doesn't do any of that and isn't supposed to. So you add another layer of data munging in whatever produces the XML before the XSLT operates, or hack it in Javascript afterwards, and either way now you have two problems.
Maybe XSLT skews high for income because it takes huge sums of money to get programmers to even touch the thing.
IIRC, it actually is turing complete (or nearly powerful), and it works in the paradigm of functional programming. Have done a large-ish project with it circa 2002-2004.
>I only wonder, where is XSLT usually used? Can anyone outline the most typical types of projects and environments?
Well, it's used a lot in the enterprise, where there is also a lot of XML.
We used to automatically convert SQL queries into XML using the AS column naming (like SELECT p.Id, p.Name, k.Id [kids\kid\@Id], k.Name [kids\kid\Name] FROM Person p JOIN Kids k ON k.FatherId = p.Id).
Then we could transform server-side to send down the HTML as well as do client-side updates in javascript by sending XML and the running the XSLT clientside to do partial updates (you can specify which part of the XSLT you want to run).
Worked pretty well as at the time, most browsers ran XSLT much faster than they ran Javascript.
I even got a pretty funky pivot table working in it that could handle 10,000s of rows when in javascript it would die after a 1,000 (we're talking IE6/7 era here).
There's actually a Daily WTF article where someone posted Sketchers.com's use of XSLT as a WTF and a lot of people chimed in in the comments that they did this and it was actually really good and not a WTF at all:
http://thedailywtf.com/Articles/Sketchy-Skecherscom.aspx
Note the featured comment was a response from the lead dev!
As for what situations in industry, our use was pretty uncommon as you can see from the WTF, but it's often used to transform XML in one format to another so they can get different systems actually talking to each other.