代码之家  ›  专栏  ›  技术社区  ›  Shaun Hare

未添加xslt属性

  •  1
  • Shaun Hare  · 技术社区  · 16 年前

    尝试使用下面的xslt代码将无线电输入标记为使用xslt 1.0选择的,但这并没有产生所需的结果

    脱蜡结果

    <input type="radio" value="available" title="email" selected="selected" />
    

    实际产量

      <input type="radio" value="available" title="email" selected />
    

    有人知道为什么不请?

    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>
    
    2 回复  |  直到 16 年前
        1
  •  2
  •   Eamon Nerbonne    16 年前

    这是由于你的输出模式。您是否指示xslt处理器输出html(而不是xml)?如果是这样的话,输出序列化程序将根据html的特性进行调整;例如,它将生成 <br> 而不是 <br/> 如果与属性名相同,它可能会遗漏属性内容。

    这不应该是个问题;顺便说一下,这是合法的html。

    有关详细信息,规范中有一节 what exactly html output mode is supposed to do . 它所说的其他事情…

    html输出方法应该以最小化的形式输出布尔属性(即只有一个允许值等于属性名的属性)。例如,在样式表中写入的开始标记

    <OPTION selected="selected">
    

    应输出为

    <OPTION selected>
    
        2
  •  0
  •   philcolbourn    16 年前

    试试这个:

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

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