【问题标题】:Errors with outputting XML values into CSS with XSL使用 XSL 将 XML 值输出到 CSS 时出错
【发布时间】:2016-11-18 03:10:28
【问题描述】:

尝试从example.xml 获取所有<colors> 值以将它们输出到example.xsl,但在将结果输出到我的网站时遇到问题。

下面是我正在使用的文件的抽象...

example.xml

<plant id="1">
    <colors>
       <green>#00FF00</green>
       <red>#FF0000</red>
       <blue>#0000FF</blue>
    </colors>
</plant>

example.xsl

<xsl:for-each select="colors/*">
    <span class="colors" style="background-color:{colors/*};"></span>
</xsl:for-each>

在两个 { } 括号之间出现style="background-color:{colors/*};" 错误。

那么,如何将&lt;colors&gt;下所有元素的颜色值输出到CSSCSS中?

【问题讨论】:

    标签: html css xml xslt xpath


    【解决方案1】:

    您已经在for-each 循环中选择了colors/* 元素,因此循环内的上下文元素就是.

    试试:

    <xsl:for-each select="colors/*">
        <span class="colors" style="background-color:{.};"></span>
    </xsl:for-each>
    

    或者更准确地说:

    <xsl:for-each select="colors/*">
        <span class="colors" style="background-color:{./text()};"></span>
    </xsl:for-each>
    

    【讨论】:

      【解决方案2】:

      其实你应该有这个:

      <span class="colors" style="background-color:{.};"></span>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-12-20
        • 1970-01-01
        • 2018-03-13
        • 1970-01-01
        • 1970-01-01
        • 2012-05-01
        相关资源
        最近更新 更多