A simple XSLT question: how can I add a closing "/" at the end of a single tag?

I teach myself XSLT, and I'm still trying to wrap my brain around small parts. I have a template in my XSL stylesheet that looks like this ...

<td><img src="{normalize-space(image)}"/></td>

which creates XHTML that looks like this:

<td><img src="somefile.jpg"></td>

How can I change my XSL template to add the final "/" 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 pattern omit the output?

Thanks in advance for your help!

+3
source share
2 answers

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"/>

XSL , () XML. HTML , XML/XHTML.

+5

:

<xsl:element name="img">
    <xsl:attribute name="src">blarg</xsl:attribute>
</xsl:element>  

<img src="blarg"/>

+1

Source: https://habr.com/ru/post/1723488/


All Articles