2010-03-29 103 views
1

试图标记无线电输入作为与XSLT使用下面的XSLT代码1.0选择但这并不产生所期望的结果XSLT属性不被添加

desrired结果

<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

这是由于您的输出模式。你有没有指示你的XSLT处理器输出HTML(而不是XML)?如果是这样,则输出序列化器适合于调整HTML的特性;因此,例如它生成<br>而不是<br/>,并且如果与属性名称相同,则可能会遗漏属性内容。

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

欲了解更多详情;该规范有关于what exactly html output mode is supposed to do的部分。 Amonst其他的东西,它说...

的HTML输出方法应输出布尔属性(即只有一个允许值等于属性的名称属性)以最小化形式。例如,起始标签写在样式表作为

<OPTION selected="selected"> 

应该输出

<OPTION selected> 
+1

感谢非常很多,就是这样。也意识到我应该使用检查=“检查” – 2010-03-29 08:49:00

+0

啊,是的,这个错误可以很容易地跳过XSLT奥尔卡纳;-) - 好抓! (您可以使用HTML验证器来捕捉那种错误 - 应该可能检测到没有意义的属性。) – 2010-03-29 18:04:19