加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

xml – 如何组合xsl:attribute和xsl:use-attribute-sets来有条

发布时间:2020-12-16 23:10:35 所属栏目:百科 来源:网络整理
导读:我们有一个xml节点“item”,其属性为“style”,即“Header1”.但是这种风格可以改变.我们有一个名为Header1的属性集,它定义了在xsl:fo生成的PDF中的外观. 这是有效的(在fo:table-cell节点中内联提到了use-attribute-sets): xsl:template match="item[@typ
我们有一个xml节点“item”,其属性为“style”,即“Header1”.但是这种风格可以改变.我们有一个名为Header1的属性集,它定义了在xsl:fo生成的PDF中的外观.

这是有效的(在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:属性,因为@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:什么时候?

解决方法

从 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”应用模板规则并在那里生成所需的属性.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读