Reputation: 110
Hi I have a transform where I'm trying to create a static element where the open and closing tags persist in the output.
For example, I've tried...
<?xml version="1.0"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes" encoding="ISO-8859-1"/>
<xsl:template match="/">
<root>
<child>
<!--static values-->
<xsl:element name="ad_version"></xsl:element>
<action_code></action_code>
</child>
</root>
</xsl:template>
</xsl:stylesheet>
This outputs the following:
<?xml version="1.0" encoding="iso-8859-1"?>
<root>
<child>
<ad_version />
<action_code />
</child>
</root>
I need...
<ad_version></ad_version>
<action_code></action_code>
Thoughts?
Thanks.
Upvotes: 1
Views: 1586
Reputation: 24410
Officially there's no difference between empty (<a></a>
) and atomic (<a />
) tags; so your vendor has a bug if they can't accept this data / really it should be on them to fix since they're not standards compliant.
However, if you have to hack your code to match their standards, there are ways...
If you're using Microsoft's .Net XslCompiledTransform you can populate the tags with <xsl:value-of select="''" />
; i.e. code which outputs blank at runtime. See XSLT Fiddle Example
If you're using Saxon, you can switch the output from xml
to xhtml
, e.g. <xsl:output method="xhtml"
. See XSLT Fiddle Example.
For other engines, let us know and we can try to find a hack. For many changing the output to html
would likely work, but would lose the XML Declaration (<?xml version="1.0" encoding="ISO-8859-1"?>
), so can cause other issues, especially if you're using characters outside of the normal ASCII range.
Upvotes: 5