I am trying to get the complete address using XPath. I am new to XPath. This is what I have done so far:
<p class="adr" prop1="address">
<span class="street-address" name="streetname">2222 Warnar Ave</span>
<span class="country" name="country">USA, </span>
<span name="State">CA</span>
<span name="zip">1111</span>
</p>
My XPath
/p/span/text()
Result like an array:
Text='2222 Warnar Ave'
Text='USA,'
Text='CA'
Text='1111'
And I want the result as a complete one line address
2222 Warnar Ave USA, CA 1111
I have used concat()
in my XPath but nothing is showing!
The concat operator '||' was introduced in XPath 3.0. It used in string concatenation expressions to concatenate two strings. The 'to' operator is used in sequence expressions to construct a sequence of items of type 'xs:integer' from a range specified by the left and right operands.
The XPath 2.0 function fn:concat(arg1, arg2, ,,,) takes two or more arguments, converts them to their string representation, and concatenates them, returning a single string. The fn:concat transform is the representation of the fn:concat XPath function in the Graphical Data Mapping editor.
Concat function in XSLT helps to concatenate two strings into single strings. The function Concat() takes any arguments that are not the string is been converted to strings. The cardinality function passed over here in each argument should satisfy zero or one function() respectively.
concat(/p/span[1],' ',/p/span[2],' ',/p/span[3],' ',/p/span[4])
Of course, instead of /p/span[1]
you could specify /p/span[@class='street-address']
etc.
string-join(/p/span, ' ')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With