Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XSLT, XPath and InStr

Tags:

xml

xslt

xpath

Is there a way to find a node matched on part of a 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 string "Premier League" or even "Prem", how would I match the correct node and get id 100.

I have managed this using for-each and contains, but this is very inefficient and does not work fast enough for our requirements.

like image 499
Xetius Avatar asked Dec 01 '08 11:12

Xetius


People also ask

What does :: doubles Colon in sibling XPath represent?

A double colon :: is used to separate the axis specifier from the node test. This XPath expression is a relative location path which selects all 'office' element children of the context node. Every axis has a principle node type.

How do you find the length of a string in XSLT?

Name. string-length() Function — Returns the number of characters in the string passed in as the argument to this function. If no argument is specified, the context node is converted to a string and the length of that string is returned.


1 Answers

String handling is not something XSLT is amazing at but there are a few options.

In this case you might try:

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

see here for more options and details

like image 56
annakata Avatar answered Oct 11 '22 14:10

annakata