Reputation: 4334
i have an xml document which looks abit like
<a>
<somenode att="1"></somenode>
</a>
<a01>
<apple att="2"></apple>
<somenode att="1"></somenode>
</a01>
what im trying to do is match when node name is 'a' or a followed by one number (a0) and a followed by two number (a01), any ideas on how I can do this ?
I have the following so far
<xsl:apply-templates select="node()[starts-with(name(),'a')]">
but this will select apple aswell, also how to do multiple matches like and OR/AND ?
Upvotes: 0
Views: 526
Reputation: 101652
In XSLT 2.0 this would be pretty simple:
<xsl:apply-templates select="node()[matches(name(),'^a\d?\d?$')]">
In XSLT 1.0, regex isn't available, so it's a little trickier, but the following should work:
<xsl:apply-templates select="node()[starts-with(name(), 'a') and
string-length(name()) <= 3 and
translate(name(), '0123456789', '') = 'a']" />
The three parts joined by "and" here ensure that:
Upvotes: 4