gpt4 book ai didi

xml - 我怎样才能结合xsl :attribute and xsl:use-attribute-sets to conditionally use an attribute set?

转载 作者:数据小太阳 更新时间:2023-10-29 01:51:13 25 4
gpt4 key购买 nike

我们有一个 xml 节点“item”,其属性为“style”,即“Header1”。但是,这种风格可以改变。我们有一个名为 Header1 的属性集,它定义了它在 PDF 中的外观,通过 xsl:fo 生成。

这有效(在 fo:table-cell 节点中内联提到了 use-attribute-sets):

<xsl:template match="item[@type='label']">
<fo:table-row>
<fo:table-cell xsl:use-attribute-sets="Header1">
<fo:block>
<fo:inline font-size="8pt" >
<xsl:value-of select="." />
</fo:inline>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>

但这不是(使用 xsl:attribute,因为属性 @style 也可以是 Header2)。它不会生成错误,创建了 PDF,但未应用属性。

<xsl:template match="item[@type='label']">
<fo:table-row>
<fo:table-cell>
<xsl:attribute name="xsl:use-attribute-sets">
<xsl:value-of select="@style" />
</xsl:attribute>
<fo:block>
<fo:inline font-size="8pt" >
<xsl:value-of select="." />
</fo:inline>
</fo:block>
</fo:table-cell>
</fo:table-row>
</xsl:template>

有人知道为什么吗?我们如何才能实现这一点,最好不要使用长 xsl:if 或 xsl:when 东西?

最佳答案

来自 http://www.w3.org/TR/xslt#attribute-sets

通过在 xsl:element、xsl:copy [...] 或 xsl:attribute-set 元素上指定 use-attribute-sets 属性来使用属性集

来自 http://www.w3.org/TR/xslt#section-Creating-Elements-with-xsl:element

<!-- Category: instruction -->
<xsl:element
name = { qname }
namespace = { uri-reference }
use-attribute-sets = qnames>
<!-- Content: template -->
</xsl:element>

http://www.w3.org/TR/xslt#copying

<!-- Category: instruction -->
<xsl:copy
use-attribute-sets = qnames>
<!-- Content: template -->
</xsl:copy>

因此,很明显它不可能是 AVT(动态定义)。

注意:关于文字结果元素,规范说:也可以通过在文字结果元素上指定 xsl:use-attribute-sets 属性来使用属性集。 关于允许 AVT 很少含糊其辞。假设没有。

关于第二个示例:您使用该模板将“xsl:use-attribute-sets”属性添加到结果树中。它不是由 XSLT 处理器解释的。

那么,解决方案是什么?您必须摆脱“xsl:use-attribute-sets”。为“@style”应用模板规则并在那里生成所需的属性。

关于xml - 我怎样才能结合xsl :attribute and xsl:use-attribute-sets to conditionally use an attribute set?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2998046/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com