Interesting question. What you are seeing isn't a bug, and is due to the
difference between the typed value and string value of a node (see 1st link
- When calling `xs:string(…)`, e.g. doing a cast (see 2nd link below), the
atomized value of the parameter is taken, and atomization looks at the typed
value of the node. Since the node of type date, the typed value must be a
date, but since in this case it isn't, you have an error, which stops the
evaluation of the expression.
- When you do `$gaga/text()`, you're accessing the text node inside your
element, which will return whatever is stored inside that element irrelevant
A very similar situation happens with booleans, which we discuss in the doc
(see 3rd link below), and of course would happen with any other type. This
isn't trivial, or intuitive (maybe unless you already know about it?!), but
hope it will help.