【发布时间】:2013-08-12 01:47:19
【问题描述】:
我正在尝试将属性添加到另一个元素的 'xsl:element name="div"' 元素 模板,'xsl:template match="KTheme"' 模板,但我收到一个 XSLT 错误,没有关于失败或失败原因的错误信息。有没有办法做到这一点?
基本上,当从 'xsl:template name="DisplayFrame"' 模板执行 'xsl:apply-templates/' 行时,它会匹配 'KTheme' 元素并应将“style”属性添加到“div”元素:
<xsl:template match="Frame">
<xsl:call-template name="DisplayFrame">
<xsl:with-param name="FrameId" select="'frameHeader'" />
</xsl:call-template>
</xsl:template>
<xsl:template name="DisplayFrame">
<xsl:param name="FrameId" />
<xsl:element name="div">
<xsl:attribute name="id">
<xsl:value-of select="$FrameId" />
</xsl:attribute>
<xsl:apply-templates/>
</xsl:element>
</xsl:template>
下面的模板是将“style”属性添加到“div”元素的地方。这个模板给了我一个错误,因为一旦我删除了“xsl:attribute”元素,XSLT 就会成功编译。
<xsl:template match="KTheme">
<xsl:attribute name="style">
<xsl:value-of select="." />
</xsl:attribute>
</xsl:template>
一个示例 XML 文件:
<Document>
<Frame>
<KTheme>background-color: red;</KTheme>
</Frame>
</Document>
实际上,“KTheme”元素是动态创建的,因此必须按照我的理论建议,通过添加来自另一个模板的属性来完成,但显然这是不正确的。这可以做到吗?感谢您的宝贵时间。
【问题讨论】:
标签: xslt attributes