xsl-list
[Top] [All Lists]

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

2007-06-15 05:35:35
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

 

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>