Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP XPath ends-with [duplicate]

Tags:

php

xpath

Possible Duplicate:
How to use XPath function in a XPathExpression instance programatically?

I'm trying to find all of the rows of a nested table that contain an image with an id that ends with '_imgProductImage'.

I'm using the following query:

"//tr[/td/a/img[ends-with(@id,'_imgProductImage')]"

I'm getting the error: xmlXPathCompOpEval: function ends-with not found

My google searches i believe say this should be a valid query/function. What's the actual function i'm looking for if it's not "ends-with"?

like image 358
Matt Avatar asked Mar 25 '11 16:03

Matt


1 Answers

from How to use XPath function in a XPathExpression instance programatically?

One can easily construct an XPath 1.0 expression, the evaluation of which produces the same result as the function ends-with():

$str2 = substring($str1, string-length($str1)- string-length($str2) +1)

produces the same boolean result (true() or false()) as:

ends-with($str1, $str2)

so for your example, the following xpath should work:

//tr[/td/a/img['_imgProductImage' = substring(@id, string-length(@id) - 15)]

you will probably want to add a comment that this is a xpath 1.0 reformulation of ends-with().

like image 69
ax. Avatar answered Sep 20 '22 19:09

ax.