1
<p class="pd-price">
    <img alt="€" src="http://www.redcoon.es/templates/tpl/img/pd/pd-price/euro_small.png">
    <img class="offsetStandard" alt="2" src="http://www.redcoon.es/templates/tpl/img/pd/pd-price/2.png">
    <img class="offsetStandard" alt="6" src="http://www.redcoon.es/templates/tpl/img/pd/pd-price/6.png">
    <img class="offsetStandard" alt="1" src="http://www.redcoon.es/templates/tpl/img/pd/pd-price/1.png">
    <img class="offsetStandard" alt="-" src="http://www.redcoon.es/templates/tpl/img/pd/pd-price/minus_point.png">
</p>

How to write an Xpath for this paragraph so that it will return "€261-". the Combine String of all the alt tag.

2 Answers 2

1

Use

 string-join(p/img/@alt, "")

that will first select the text of all alt attributes and then combine it in a string

Sign up to request clarification or add additional context in comments.

3 Comments

any other function instead of string-join. The Parser doesn't support this function. Can we Use concat any how ???
With concat you could do it like concat(p/img[1]/@alt,p/img[2]/@alt,p/img[3]/@alt,p/img[4]/@alt,p/img[5]/@alt,p/img[6]/@alt,p/img[7]/@alt). (if there are more img in the concat call than in the html they are ignored). But it is better to switch to another parser that supports the most basic function.
If it supports xpath 2, you could also move the p/ out to make it a little bit simpler p/concat(img[1]/@alt,img[2]/@alt,img[3]/@alt,img[4]/@alt,img[5]/@alt,‌​img[6]/@alt,img[7]/@alt)
0

In Xpath 2, you have string-join

string-join(p[@class='pd-price']/img/@alt, '')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.