未添加 XSLT 属性

发布于 2024-08-27 02:45:35 字数 1869 浏览 6 评论 0原文

尝试使用下面的 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>

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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

马蹄踏│碎落叶 2024-09-03 02:45:35

这是由于您的输出模式所致。您是否指示 XSLT 处理器输出 HTML(而不是 XML)?如果是这样,输出序列化器会根据 HTML 的特性进行调整;例如,它会生成
而不是
,并且如果与属性名称相同,它可能会忽略属性内容。

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

了解更多详情;该规范有一个关于 具体内容的部分html 输出模式应该是。它说的还有其他事情......

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

<选项已选择=“已选择”>

应输出为

<选项已选择>

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>
上课铃就是安魂曲 2024-09-03 02:45:35

Try this:

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

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文