In XPath I want to insert some newlines when using concat(…)
and/or string-join(…)
. From Line breaks (\n) via concat() in XPath? I learned I can insert a newline using codepoints-to-string(10)
. For two of them I can do concat(codepoints-to-string(10), codepoints-to-string(10))
, but that seems sort of long. From concatenate a string/character n number of times in xpath I learned I can apparently do string-join((1 to 2)!codepoints-to-string(10))
or something close, but I'm not sure that that brings much improvement.
Is there some more compact way to represent two or more newlines together in XPath?
It turns out that you can provide multiple code points to code-points-to-string(…)
, but you have to provide them as a sequence: codepoints-to-string((10, 10))
.
However a more direct approach, as Michael Kay pointed out, is to simply insert as many newlines you want into the XPath expression inside '…'
, with no escaping needed. (I had assumed this wasn't possible, as inserting newlines into many query languages will wreck the query.)
How you insert literal newlines depends on the host language. For example in Java you need to provide some escaping at the Java String
or char
level, e.g. "'…\n\n'"
(or one of many, many other possibilities, such as StringBuilder.append((char)10)
.
If you are specifying the XPath query in XML, you would add 

right in the XPath expression.
The point is that the string that reaches the XPath processor has no escaping—it contains literal U+00A0 code points.