Reputation: 47
I have an input which can sometimes have value and sometimes not. Like value1=ABC or value1=""
During my xsl transformation I have my code with the following line
<element name="test"><xsl:value-of select="$value1"/><element>
The output of the above code when value is present is
<element name="test">ABC</element>
When the value is not present, the output is
<element name="test"/>
Now, I want it to look like
<element name="test"></element>
instead of
<element name="test"/>
Is it possible to get the required output? If yes, then how to do it?
Upvotes: 0
Views: 1379
Reputation: 52858
Try adding <xsl:output method="html"/>
.
Example...
XSLT 1.0
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html"/>
<xsl:strip-space elements="*"/>
<xsl:template match="/">
<xsl:variable name="test1"/>
<xsl:variable name="test2" select="'value'"/>
<element name="test1"><xsl:value-of select="$test1"/></element>
<element name="test2"><xsl:value-of select="$test2"/></element>
</xsl:template>
</xsl:stylesheet>
produces (when applied to any XML instance):
<element name="test1"></element>
<element name="test2">value</element>
Upvotes: 1