views:

1136

answers:

5
+11  Q: 

Client-side XSLT

I converted my whole site to XML/XSL and I would like to know all of the current issues with performing Client-side XSLT.

Here are the ones i already know of (from first-hand experience):

  • Cross-domain XSL files (this is a security issue and not cross browser)
  • disable-output-escaping (this does not work in FF... they consider it a security issue)

Also as for browser support this is all i know of:

  • Opera 9+
  • FF 1.0+
  • SF 2.0 + (i may be wrong on this)
  • Chrome
  • IE 6.0 +

Any others would be helpful too :)

Edit:

As for the 2nd pitfall there is a decent workaround that lets you pass xhtml to your xsl. It works by actually converting and making sure your XHTML is valid XML and placing it into your XML as XML. Then in your XSL you copy the xml ;) and output it as XHTML.

+8  A: 
  • Speed: The browser needs to apply the XSLT transformation before rendering the HTML, thus the user will have to wait longer to see the page. The XSLT engines used by the browsers might not be top-notch. On Mac OS X, the browser might freeze while the XML is transformed and cause the "spinning beach ball" cursor, thus the user might punch the screen and injure him or herself.

  • Accessibility: What about the browsers not in that set, such as screen-readers? Do those users matter to you?

a paid nerd
Were offloading all template generation to the client (thus saving a huge amount of CPU), I have a list of browsers that i know XSLT work s with so i send them the actual XML/XSL. If a browser is not on the white list then the server performs the XSLT for them and sends HTML.Thanks though, i will be adding this to my pros/cons list.
Chad Scira
+1  A: 

I found passing parameters to xsltfiles difficult to keep crossbrowsing able. I now support FF and IE but Chrome fell out because of it..

Peter
do you have a codeblock as an example, i was able to get this to work fine in chrome.
Chad Scira
Yes I have, but Chrome was not too important for us, so I just left it out. for (i = 0; i < parameters.length; i++) { xsltProcessor.setParameter(null, "p" + i, parameters[i]); for nonIE and for (i = 0; i < parameters.length; i++) { processor.addParameter("p" + i, parameters[i]); } for IE
Peter
Maybe I'm off but when I read "client-side XSLT", I assumed the question referred to simple XML -> XHTML translation with a static XSLT linked via an <?xml-stylesheet ?> rather than the JavaScript XSLT engine. If so, passing parameters is irrelevant since the only input set is XML documents.
Jeff Mc
jeff is correct i was speaking of the the xml-stylesheet method
Chad Scira
+1  A: 

The XSLT file is another object which needs to be downloaded and the browser will only fetch 2 or 3 items in parallel. My experience is that the overall performance (download and generation) is noticably slower.

Also, depending on the complexity and redundancy of the data, you might be downloading much more than you really need to - ie. if the HTML had already been rendered.

paul
I dont think this is a valid argument. Do you not use CSS because its another file to be downloaded? It can be cached just like CSS.
Chad Scira
@Chad Are you saying your XSLT will not hold actual web standards like CSS then? Will the XSLT transform your XML file into HTML and a table-based design or will it use CSS? This is a very valid argument in my opinion since if you are taking XML and converting it into HTML yet not using web standards, then you may be doing it wrong. Also, if your goal is to convert your HTML content into a different format, perhaps using XHTML first and then transforming it may be a better option.
JamesEggers
I would be using all web technologies. CSS (Design), XSL/XHTML (Structure), XML (Data), JS (Behavior). The amount of data separation is beautiful.
Chad Scira
The questioner wanted to discuss the issues - I think this is an issue. I'm all for data separation but if the performance becomes a problem then I'd be pragmatic
paul
depends on how you use the technology. global.css, {pagespecific}.css (both get cached...), use the same method for XSL
Chad Scira
+1  A: 

On the performance front... consider that the majority of clients these days have 2 CPU's and 2 GB of RAM each, and that most servers don't... Have two CPU's + 2 GB per client that is. So it's certainly logical that offloading the XSLT transforms should improve scalability, and caching CSS + XSLT + JS should reduce overall traffic.

Having said that I've tried using XSLT to produce XHTML containing SVG in the past, and had an epic-fail. The largest page was simply too big (3,000+ entries in an index), and IE uses a DOM to do the XSLT transform, which causes it to start trashing. The same transforms done in xerces-j (on the server, on the same dev box) was about 1000 times faster.

It's high-time the browser-monkeys got with the program ;-)

An interesting discussion. Thanks for raising it.

Cheers. Keith.

corlettk
I have yet to try SVG, because its not cross browser. I know there is a plugin that adobe provides, its such a beautiful technology. http://raphaeljs.com/ <- soo cool...
Chad Scira
+1  A: 

i have worked about 1 year at a project where we used xslt+xml-> html (although server-side only)

the major drawback i encountered: there are no good tools for xslt generation which lean towards web developement. no previewing of html. no validation. the resulting xslt was a total mess noone could understand. that was not so much the xslt designers fault, but rather results from the xslt processing model.

the layering between xslt/xml/urls becomes more complicated than it should be. there is no way you could program component-oriented.

often multiple xslt files were needed, this would lead to many downloads on the client-side. otherwise it would lead to massive code duplication thoughout the project.

i would see this as a form of early optimisation. you shoud start by using a "normal" web framework like wicket, jsf, tapestry, gwt etc.., later if it turns out your servers preformance is cpu-bound you might ocnsider rewriting the most often used parts of the apllication that way.

otoh, it has real benefits if you need to provide both an xml api + a html interface.

Andreas Petersson
basically I replaced smarty (a PHP templating engine) with client-side XSLT. And in doing so i had to totally isolate the data, which is a wonderful thing. For example i could write an mobile interface easily now, because everything is separated. So far id say there is a learning curve but your basically future proofing your application if you use this method.
Chad Scira