XSLT 2.0 - pattern matching with content ()

I am wondering if it is possible to write pattern matching using a function contains().

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

+5
source share
1 answer

Yes, you can use the contains()predicate filter inside the matching criteria for elements.

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

You can also use starts-with()

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

If you are using XSLT 2.0, you can use a function matches()that supports REGEX templates for more complex matching.

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

All Articles