Wednesday, March 10, 2010

Chome and XSLT

I've built a web portal for my own use that integrates search engines, categorized favorite links and custom styled RSS feeds into a single page. It's a hodgepodge of ASP, VBScript and JavaScript with an XML as the backend and jQuery/UI to liven things up.

Initially working with FireFox as my default browser, everything was working fine until I decided to install Chrome. That when I got the error message: Extra content at end of document.


This gave me quite a headache until I traced it to the XSL processing in my JavaScript. I didn't quite understand what was causing the problem until I realized that Chrome didn't like what I was doing inside my {xsl:template}.

It turns out Chrome expects a only single child node (or document if you like) inside an xsl template and was complaining about anything coming after it. So you can't have this: (sorry about the curly braces, it seems blogger doesn't play nicely with code tags)

{xsl:template match="/rdf:RDF|/rss"}
{img src="...."}{/img}
{div}
...
{/div}
{xsl:template}

To fix this problem, all I did was wrap everything in another div.

{xsl:template match="/rdf:RDF|/rss"}
{div}
{img src="...."}
{div}
...
{/div}
{/div}
{xsl:template}

... et voila ...