Today, I got around to trying to tackle some of the XHTML validation errors we've been receiving on our sites at work.  One of the peskiest errors was what appeared to be a simple unclosed <img> tag–easy to fix, right?  Well, I promptly navigated to the xslt file, opened it up, and quickly found the offending tag. 

…it was already closed.

…hmmm…

Honestly, I couldn't figure out what was going on.  Just to make sure, I recopied the most recent, seemingly correct version. 

No change. 

I went back to the file, made ABSOLUTELY sure that the tag was closed and that there were no weird quotes floating around.

No change.

By now, I was desperate.  I even started commenting out random bits of code around the <img> tag until I was POSITIVE that nothing else was causing this issue.

No change.

Blurg.

Well, it turns out the fix is pretty easy, and it all has to do with the "method" attribute of the <xsl:output> directive.  On my xslt file (which I did not create, BTW), the method was set to "HTML" like so:

<xsl:output method="HTML" …./>

For whatever reason, this method of output can do funky things like remove the self-closing parts of tags.  Dumb.

Anyway, I simply switched the output method to XML and it resolved the issue.  Not only that, but it knocked out about 10 other validation errors that I hadn't even started looking at yet.  Woot!

So if you're interested in learning more about this xsl:output nonsense, be sure to check out the W3C definition…it's a riveting read, but does–at least–provide the right answer :)