XSL 匹配 xsl:variable 元素并更改 @select 属性

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

我需要复制完整的 xsl 文件,但更改特定变量的

@select
属性的特定值。

我的伪代码想法:

    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>

    <xsl:template match="variable[@name='Name']">
        <xsl:attribute name="select">
            <xsl:value-of select="'new value'"/>
        </xsl:attribute>
    </xsl:template>

要完全清楚;如何选择匹配语句中的变量元素?

使用

[CDATA]
或许可以,但我更喜欢更实用的解决方案。

我仅限于 xslt 1.0。

有什么想法吗?

xslt xslt-1.0
1个回答
0
投票

如何选择可变元素

您可以通过其限定名称来选择它,即包含绑定到命名空间和本地名称的前缀的名称 - 例如:

<xsl:template match="xsl:variable[@name='Name']/@select">
    <xsl:attribute name="select">new value</xsl:attribute>
</xsl:template>

请注意,您的尝试即使有效,也会删除

name
属性。

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