XSLT 2.0-包含contains()的模板匹配 [英] XSLT 2.0 - Template Matching With Contains()

查看:445
本文介绍了XSLT 2.0-包含contains()的模板匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是否可以使用contains()函数编写模板匹配项.

I'm wondering if it is possible to write a template match with the contains() function.

我有一个文档,其中包含多个元素,需要将其重命名为一个公共元素.以下所有内容都需要重命名为OP:OP1.2,OP7.3,OP2.4,OP5.6`等.

I have a document that has multiple elements that need to be renamed to a common element. All of the following need to be renamed to just OP: OP1.2, OP7.3, OP2.4, OP5.6`, etc.

推荐答案

是的,您可以在元素的匹配条件中的谓词过滤器中使用contains().

Yes, you can use contains() inside of a predicate filter in the match criteria for elements.

<xsl:template match="*[contains(local-name(),'OP')]>
  <OP>
    <xsl:apply-templates select="@*|node()"/>
  </OP>
</xsl:template>

您还可以使用 starts-with()

You could also use starts-with()

*[starts-with(local-name(),'OP')]

如果您使用的是XSLT 2.0,则可以使用 matches() 函数,它支持REGEX模式以进行更复杂的匹配.

If you are using XSLT 2.0 you could use the matches() function, which supports REGEX patterns for more complex matching.

*[matches(local-name(),'^OP')]

这篇关于XSLT 2.0-包含contains()的模板匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆