xml - Count number of nodes with substring of attribute equivalent to some value -


example: trying count number of b nodes images.

xml:

<a>  <b mediatype='image/jpeg'>   <c>hello.jpg</c>  </b> </a> 

xpath:

count(//b[substring(@mediatype, 0, 5) = 'image']) 

using xpath tester: http://codebeautify.org/xpath-tester evaluates 0.0

thanks answers, have chosen best answer based on information given improved xpath using starts-with.

in xpath positions (for lists , strings) start 1.

if try substring(//b/@mediatype, 0, 5) imag.

so need count(//b[substring(@mediatype, 1, 5) = 'image'])

however in specific case suggest starts-with():

count(//b[starts-with(@mediatype, 'image/')])


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -