Reputation: 187
I've been wondering because whenever I look at a webpage's source-code it's mostly HTML. Well, could I build a Website completely with XML and XSLT as the Frontend? And are there any popular sites that use XML and XSLT as Frontend because I've not seen anything likely. I`m very curious because I like XML than HTML!
Upvotes: 5
Views: 1885
Reputation: 29042
Yes. But it is a sad story.
You can associate an XML file with an XSLT-1.0 file to create the desired output browser-side with the following instruction:
<?xml-stylesheet type="text/xsl" href="transform.xslt"?>
This would transfer the load of compling the HTML to the client which had to assemble the HTML by itself, client-side. Today, this is still working in the browser.
The advantage of this approach is that you can change the data (XML file) without changing the algorithm of its representation (the HTML produced by the XSLT, styled by CSS). Very efficient, and highly customizable, because the XSLT could define different transformation rules(templates) to handle different values or sets of data without reloading the XSLT.
Theoretically, the XML could be dynamically updated via AJAX/JavaScript to change the HTML. And this is possible, but not in the best way, because you have to call the browser's XSLT processor manually to update the website with JavaScript. There is no native way to do this without using JS.
Another "problem" of this approach is creating the HTML5 <!DOCTYPE html>
at the beginning of a HTML5 file. With the current browsers, this requires a hack to make it work. You have to (ab)use the xsl:output
functionality in a very specific way:
<xsl:output method="html" encoding="utf-8" omit-xml-declaration="yes" doctype-system="" doctype-public="" media-type="text/html"/>
Only then the output of the XML+XSLT tranformation will be recognized as HTML5 markup.
The reason why I introduced this posting as sad news is that the whole scenario could have been far better solved if
&
delimited parameters separatedInstead of making this approach easier for developers, the opposite has happened, and the combination of XML+XSLT has been further restricted for "security reasons" in the main browsers - which causes many people problems.
Upvotes: 4
Reputation: 111696
Yes, XSLT can be (and has been) used both on the server and in the browser to transform XML into HTML.
Upvotes: 1