[xsl] How to overrite default rendering toretain name=value attribute pairs

Subject: [xsl] How to overrite default rendering toretain name=value attribute pairs
From: "Karlmarx Rajangam" <karlmarx.rajangam@xxxxxxxxxxxxxxxxxx>
Date: Fri, 15 Jun 2007 08:35:19 -0400
I have a problem. Basically I want to get an output with selected="true"
for <option/>, instead of WITHOUT "true". Even though <option selected/>
is a valid html, I need to get name=value pair (selected=true) as we try
to form & pass an XML input for some other validation.

We must create something like,
<choice>
	<option selected = "true">cc</option>
	<!-- NOT THIS WAY <option selected>cc</option> -->
	<option>bbb</option>
</choice>

Tried 2 ways:(A)
<xsl:for-each select="OPTION">
inputXML += '<option>
	<xsl:if test="@SELECTED='true'"><xsl:attribute
name="Selected">true</xsl:attribute></xsl:if><xsl:value-of select="."/>
</option>\n';
</xsl:for-each>

Results in <option selected>xxx</option>, without ="TRUE" thereby
becoming an INVALID XML

So, I tried (B),
<xsl:for-each select="OPTION">
<xsl:choose>
	<xsl:when test="@SELECTED='true'">inputXML += '&lt;option
selected="true"&gt;<xsl:value-of
select="."/>&lt;/option&gt;\n';</xsl:when>
	<xsl:otherwise>inputXML += '<option><xsl:value-of
select="."/></option>\n';</xsl:otherwise>
</xsl:choose>
</xsl:for-each>

thinking &lt; will be rendered a <, but resulted only as
&lt;option selected="true"&gt;xxx&lt;/option&gt;

Any suggestion how I can fix this?

Thanks in advance,
karl

Current Thread