views:

183

answers:

1

How can I find attribute values based on a regular expression of the attribute name in xslt? In this snippet, I am trying to match attributes like "url.title", or "page.title", etc... anything with ".title".


<attribute name="withRegexp">
  <value-of select='matches(@*[name()], "\.title")'/>
</attribute>

That doesn't work, any ideas what to fix?

Thanks!

+2  A: 

In XPath 2.0 you can match attribute nodes whose name ends in .title with:

@*[matches(name(), '\.title$')]

In XPath 1.0 there are no regular expression matching functions. To get attribute nodes whose name contains the substring .title you can use:

@*[contains(name(), '.title')]
Jukka Matilainen
awesome, thanks!
viatropos