如何使用xslt包装匹配的元素

问题描述 投票:0回答:1

我正在尝试使用xslt将<fo:block-container>包装器元素添加到任何匹配的<table>元素中。 <fo:block-container>需要使用与width相同的<table>属性值>

示例来源将是

<table width="654px">
 --contents
</table>

期望的结果将是

<fo:block-container width="654px">
  <fo:table width="654px">
     --contents
  </fo:table>
</fo:block-container>

到目前为止,我看到的一些相似的帖子都在“ matching”元素内添加了新元素-在这种情况下,是<table>,例如XML XSLT Wrap specific elements。但是我想使用我指定的包装器元素包装整个匹配元素。

我正在尝试使用xslt将包装器元素添加到任何匹配的

元素中。 需要使用与
]] >>

尝试:

<xsl:template match="table">
    <fo:block-container width="{@width}">
        <fo:table>
            <xsl:apply-templates select="@*|node()"/>
        </fo:table>
    </fo:block-container>
</xsl:template>

这假设您还有其他模板来处理表的节点-在此处查看示例:https://xsltfiddle.liberty-development.net/ncntCSh/1

xml xslt xsl-fo
1个回答
0
投票

尝试:

<xsl:template match="table">
    <fo:block-container width="{@width}">
        <fo:table>
            <xsl:apply-templates select="@*|node()"/>
        </fo:table>
    </fo:block-container>
</xsl:template>

这假设您还有其他模板来处理表的节点-在此处查看示例:https://xsltfiddle.liberty-development.net/ncntCSh/1

© www.soinside.com 2019 - 2024. All rights reserved.