Simple XSLT Question: How can I add the closing "/" at the end of a single tag?

xhtml, xslt

Solution

I would start with this:

<xsl:output method="xml" doctype-system="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd" 
   doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" indent="yes"/>

This will get your XSL parser to close empty tags correctly since you are (technically) producing XML. HTML does not have the concept of an empty tag like XML/XHTML does.

Problem

I'm teaching myself XSLT and am still trying to wrap my brain around the small details. I have a template in my XSL stylesheet that looks like this... ``` <td><img src="{normalize-space(image)}"/></td> ``` which produces XHTML that looks like this... ``` <td><img src="somefile.jpg"></td> ``` How do I change my XSL template to add a trailing "/" to the img tag so that the XHTML output looks like this... ``` <td><img src="somefile.jpg"/></td> ``` Also, why does the trailing slash in the template get omitted in the output? Thanks in advance for all your help!

Original source