XSLT 2.0 - Template Matching With Contains()

五迷三道 提交于 2019-12-07 05:07:55

问题


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

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.


回答1:


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>

You could also use starts-with()

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

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')]


来源:https://stackoverflow.com/questions/5036169/xslt-2-0-template-matching-with-contains

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!