views:

20

answers:

2

Hi,

I have an xml sheet with some data and some images that i want to collect only a part using xslt.

However, there is one image with a particular classname that i would like to collect especially.

For example, the xml says:

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

How do I get the src attribute of this image by selecting it by classname with xPath?

Thanks you

+2  A: 

This should work : //img[@class="itemImage"]/@src

Scharron
+2  A: 

This XPath will return the src of the first img node which has a src and has the specified class

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

However, if you know anything at all about the structure of the xml, you can and should avoid the use of //, which requires the entire document to be scanned.

AakashM
Good answer. (+1)
Dimitre Novatchev