PHP XPath结尾于 [英] PHP XPath ends-with

查看:84
本文介绍了PHP XPath结尾于的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:
如何在XPathExpression实例中以编程方式使用XPath函数?/a>

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

我正在尝试查找嵌套表的所有行,这些行包含一个ID以'_imgProductImage'结尾的图像.

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

我正在使用以下查询:

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

我遇到错误: xmlXPathCompOpEval:函数结束-找不到

我相信我的Google搜索表明这应该是有效的查询/功能.如果不是"ends-with",我要寻找的实际功能是什么?

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"?

推荐答案

来自

一个人可以很容易地构造一个XPath 1.0表达式,其表达式产生的结果与函数ends-with()相同:

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

产生与以下相同的布尔结果(true()false()):

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

ends-with($str1, $str2)

因此,在您的示例中,以下xpath应该起作用:

so for your example, the following xpath should work:

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

您可能需要添加注释,说明这是ends-with()的xpath 1.0重新编写.

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

这篇关于PHP XPath结尾于的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆