-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
XPath "otherwise" operator #170
Comments
|
👍 for |
I have already implemented it with the |
There was discussion of whether (a) people might think the test on the LHS was testing the EBV of false(), rather than being an empty sequence, or (b) whether in fact that might be a more useful definition. |
Many languages have an analogous solution for A few languages also have a dedicated operator for boolean checks, sometimes called elvis operator. There’s a Wiki page for that as well (https://en.wikipedia.org/wiki/Elvis_operator), but it’s misleading, as many of the examples are actually existence checks. |
In the discussion, one argument was that shifting to the effective boolean value was over-generalizing a proposal that solves one specific problem, and effective boolean values will just confuse the issue (and possibly users). My reason for finding that argument non-conclusive is that a keyword like If we do want the semantics of the latter expansion, I think the suggestion of changing the keyword to |
I hesitate to support this proposal because "otherwise" has implications of being part of an if...then... construction, and could be understandably misinterpreted as the : in a ternary operation. We are trying to provide a fallback condition for null, a replacement for I recommend a different keyword. Some suggestions
|
I initially proposed I like |
I think that I tried to find good synonyms for "coalesce", "backup", "alternately", and "surrogate", but "onnull" seems better. I think that the meaning of this construct is to act as a "sentinel" and would also support something based or close to this word, maybe "guard as". |
I'd be OK with
|
There will be many users who have no idea what "null" means. The only explicit mention of null that I see in the F&O spec currently is related to JSON null values which isn't what we mean here. I could live with the |
The proposal was accepted on 2022-12-21. |
The draft specification proposes an "otherwise" operator. This issue seeks WG endorsement of this addition.
See section 4.18 of the XPath draft specification.
The semantics are that (X otherwise Y) returns X, except in the case where X evaluates to an empty sequence, in which case it returns Y. A typical usage would be
//employee ! (@location otherwise "Denver")
.There are two questions the WG might choose to discuss:
I propose that once approved, we also add this operator to the list recognised by the fn:op function.
The text was updated successfully, but these errors were encountered: