XSLT, XPath, and InStr

Is there a way to find the node matching the part of the value.

If I have the following:

<competition id="100" name="Barclays Premier League"/> <competition id="101" name="CocaCola Championship" /> <competition id="102" name="CocaCola League 1" /> 

Given the line โ€œPremier Leagueโ€ or even โ€œPremโ€, I would match the correct node and get the identifier 100.

I managed to use it for everyone and it contains, but it is very inefficient and does not work fast enough for our requirements.

+6
xml xpath xslt
source share
3 answers

String processing is not something like XSLT, but there are several options.

In this case, you can try:

 //competition[contains(@name,'Prem')] 

see here for more options and details

+14
source share

Using:

//competition[contains(@name, 'Prem')]/@id

In other situations, functions such as: start-with () or end-with () (XPath 2.0 only).

+6
source share

There is also a "matches" function that uses regular expressions, but this is only available in XSL 2.0.

+1
source share

All Articles