我需要复制完整的 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。
有什么想法吗?
如何选择可变元素
您可以通过其限定名称来选择它,即包含绑定到命名空间和本地名称的前缀的名称 - 例如:
<xsl:template match="xsl:variable[@name='Name']/@select">
<xsl:attribute name="select">new value</xsl:attribute>
</xsl:template>
请注意,您的尝试即使有效,也会删除
name
属性。