Trying to mark radio inputs as selected with XSLT 1.0 using the below xslt code but this does not produced the desired result
desrired result
<input type="radio" value="available" title="email" selected="selected" />
Actual output
<input type="radio" value="available" title="email" selected />
Anyone any ideas why not please?
XSLT
<xsl:variable name="selected">selected</xsl:variable>
<xsl:for-each select="item">
<tr>
<td><xsl:value-of select="title" /></td>
<td>
<input type="radio" value="available" >
<xsl:attribute name="name">
<xsl:value-of select="title" />
</xsl:attribute>
<xsl:if test="category='available'">
<xsl:attribute name="selected">
<xsl:value-of select="$selected"/>
</xsl:attribute>
</xsl:if>
</input>
</td>
<td>
<input type="radio" value="unavailable" >
<xsl:attribute name="name">
<xsl:value-of select="title" />
</xsl:attribute>
<xsl:if test="category='unavailable'">
<xsl:attribute name="selected">
<xsl:value-of select="$selected"/>
</xsl:attribute>
</xsl:if>
</input>
</td>
<td>
<input type="radio" value="warning" >
<xsl:if test="category='warning'">
<xsl:attribute name="selected">
<xsl:value-of select="$selected"/>
</xsl:attribute>
<xsl:attribute name="name">
<xsl:value-of select="title" />
</xsl:attribute>
</xsl:if>
</input>
</td>
</tr>
</xsl:for-each>
This is due to your output mode. Have you instructed your XSLT processor to output HTML (rather than XML)? If so, the output serializer is adapted to adjust for the idiosyncracies of HTML; so that for instance it generates
<br>rather than<br/>and that it may leave out attribute content if identical to attribute name.This shouldn’t be a problem; it’s legal HTML, by the way.
For more details; the spec has a section on what exactly html output mode is supposed to do. Amonst other things it says…