Subject:Issue with data($element) Author:Hans-Juergen Rennau Date:05 Sep 2008 06:20 PM
The “data” function atomizes its operand, that is, turns it into a sequence of atomic values. For each node in the input sequence, “data” returns the data value, which is, in the absence of schema validation, the concatenation of all text node descendants, without any seperators strewn in. So the data value of the first <information> element is “ HF 45” (note the blanks in the input!), and “Core67” for the second element.
If you let your path expression produce final result, you rely on how this *sequence* of values is serialized – and the differences you observed are simply differences of serialization, I presume. (In fact, blanks SHOULD be inserted.) The alternative is to control the output yourself by building the desired string representation in your query. You can do so using the “string-join” function.
a) If you are content with the representations of the <information> as is and only want to separate them by blank, use this expression:
string-join(data($books/book/information), " ")
Result for your example: “ HF 45 Core67”
b) If you want to separate also the child items of <information> themselves by a blank, do this: