Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Class XPath按类名选择图像_Class_Xpath - Fatal编程技术网

Class XPath按类名选择图像

Class XPath按类名选择图像,class,xpath,Class,Xpath,我有一个xml表,其中包含一些数据和一些图像,我只想使用xslt收集其中的一部分 然而,有一张带有特定类名的图片我想特别收集 例如,XML表示: <img class="itemImage" height="130" src="image.png" width="195"/> 如何通过使用XPath按类名选择此映像的src属性?这应该可以工作://img[@class=itemImage]/@src这应该可以工作://img[@class=itemImage]/@src此XPath

我有一个xml表,其中包含一些数据和一些图像,我只想使用xslt收集其中的一部分

然而,有一张带有特定类名的图片我想特别收集

例如,XML表示:

<img class="itemImage" height="130" src="image.png" width="195"/>

如何通过使用XPath按类名选择此映像的src属性?

这应该可以工作://img[@class=itemImage]/@src

这应该可以工作://img[@class=itemImage]/@src

此XPath将返回具有src和指定类的第一个img节点的src


但是,如果您对xml的结构有任何了解,那么可以而且应该避免使用//,因为它需要扫描整个文档。

此XPath将返回第一个img节点的src,该节点具有src并具有指定的类

但是,如果您对xml的结构有任何了解,那么可以而且应该避免使用//,因为它需要扫描整个文档

(//img[@class="itemImage"]/@src)[1]