1

尝试使用以下 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>
4

2 回答 2

2

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

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

更多细节; 该规范有一个关于html 输出模式应该做什么的部分。它说的除其他外...

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

<OPTION selected="selected">

应该输出为

<OPTION selected>
于 2010-03-29T08:43:57.660 回答
0

试试这个:

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

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

于 2010-03-29T08:50:21.890 回答