Usage of & in xquery concat
Asked Answered
M

1

5

How can I use & (the ampersand character) in an XQuery concat statement? I'm using eXist DB and this works:

concat("Marvin ", "and", " Peter")

but this doesn't:

concat("Marvin ", "&", " Peter")

I'm getting the error: expecting '"', found '&'

Escaping the ampersand with a \ doesn't work.

Moisten answered 15/2, 2019 at 16:19 Comment(1)
Funnily enough the notification mail from SO gives the solution away. Your question is shown as: How can I use & (the ampersand character) in an Xquery concat statement? I'm using eXist DB and this works: concat("Marvin ", "and", " Peter") but this doesn't: concat("Marvin ", "&", " ... Stope
F
7

Since & is the escape character for XML character and entity references, it cannot be used as a literal character in either XML or XQuery strings. You have to use an entity to encode it. You can either use the predefined &, or reference it via its Unicode codepoint with &#[...]; (decimal) or &#x[...]; (hexadecimal):

concat("Marvin ", "&", " Peter"),
concat("Marvin ", "&", " Peter"),
concat("Marvin ", "&", " Peter")
Footcandle answered 15/2, 2019 at 16:41 Comment(1)
For improved readability you can define the variable let $amp := fn:codepoints-to-string(38) .Homograph

© 2022 - 2024 — McMap. All rights reserved.