How do I use apply-templates to select only those elements by name (not value) that end with a specific pattern? Assume the following xml…
<report>
<report_item>
<report_created_on/>
<report_cross_ref/>
<monthly_adj/>
<quarterly_adj/>
<ytd_adj/>
</report_item>
<report_item>
....
</report_item>
</report>
I want to use <xsl:apply-templates> on all instances of <report_item> where descendant elements end with ‘adj`, so, in this case, only monthly_adj, quaterly_adj, and ytd_adj would be selected and applied with the template.
<xsl:template match="report">
<xsl:apply-templates select="report_item/(elements ending with 'adj')"/>
</xsl:template>
I don’t think that regular expression syntax is available in this context, even in XSLT 2.0. But you don’t need it in this case.
*matches any node[pred]performs a node test against the selector (in this case*) (wherepredis a predicate evaluated in the context of the selected node)name()returns the element’s tag name (should be equivalent tolocal-namefor this purpose).ends-with()is a built-in XPath string function.