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.
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')]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With