开发者

XSLT Attribute not being added

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:fo开发者_运维知识库r-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...

The html output method should output boolean attributes (that is attributes with only a single allowed value that is equal to the name of the attribute) in minimized form. For example, a start-tag written in the stylesheet as

<OPTION selected="selected">

should be output as

<OPTION selected>


Try this:

<xsl:variable name="selected" select="selected"/>

http://www.w3schools.com/xsl/el_variable.asp

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜