【问题标题】:setting the style attribute of a li element using xsl使用 xsl 设置 li 元素的样式属性
【发布时间】:2009-10-06 21:33:12
【问题描述】:

我正在使用 XSL 文件将 XML 文件转换为 XHTML 文件。我正在尝试创建一个元素 li 并将“style”属性设置为值“hello:”

<li><xsl:attribute name="style">hello</xsl:attribute></li>

我明白了:

<li style=""></li>

但期望得到:

<li style="hello"></li>

有人知道发生了什么吗?

【问题讨论】:

    标签: xml firefox xslt xhtml


    【解决方案1】:

    您可以通过以下方式解决此问题

    <xsl:attribute name="class">
       <xsl:value-of select="'selected'"/>
    </xsl:attribute>
    

    上面的例子是为 li 标签添加类。 如果您对在 li 中使用样式标签过于具体,请使用

    <xsl:attribute name="style">
       <xsl:value-of select="'color:green;'"/>
    </xsl:attribute>
    

    【讨论】:

      【解决方案2】:

      似乎 Firefox 会检查进入 style 属性的值。例如,如果您输入“color:red”而不是“hello”,则样式属性将被接受。无效的 css 被丢弃。

      这可能取决于您检查 style 属性内容的准确程度,因为如果不检查 DOM 就很难看到转换的结果,这将是经过净化的转换版本。

      【讨论】:

      • 顺便说一句:文字属性符号不那么罗嗦&lt;li style="color:red"&gt;&lt;/li&gt; - &lt;xsl:attribute&gt; 有它的用途,但在这个例子中它被浪费了。
      猜你喜欢
      • 2018-11-29
      • 1970-01-01
      • 2014-02-01
      • 1970-01-01
      • 2011-05-15
      • 2010-09-25
      • 1970-01-01
      • 1970-01-01
      • 2018-03-01
      相关资源
      最近更新 更多