0

For the query "PROJECT[1]/PROPOSAL[1]/SOLUTION[1]/UNIT[1]/distinct-values(LANDING_DOOR_FRAME_FINISH_FRONT/LANDING_DOOR_FRAME_FINISH_FRONT_VALUE)" this appears to work if distinct-values() returns exactly one value, but throw an exception otherwise. (And by the way, this query is not my idea).

Is it a bad idea to have an atomic value as a node name in a query? Or is it ok? And if ok, is it ok only if it returns exactly one value?

Calling Saxon from Java for this.

David Thielen
  • 28,723
  • 34
  • 119
  • 193

1 Answers1

0

It's a perfectly valid query, whether or not distinct-values() returns exactly one value.

(If it fails, show us a repro: all the data we need to reproduce the problem, plus the error message).

But your question, about using atomic values as node names, suggest that you don't understand what the expression means. The values returned by distinct-values() don't have to be node names, and they are not used as node names.

These days I prefer to use the "!" operator when the RHS expression returns atomic values rather than nodes. It's equivalent, but clearer.

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • What exactly is going on for this query then? Is it returning the distinct values out at PROJECT[1]/PROPOSAL[1]/SOLUTION[1]/UNIT[1]/LANDING_DOOR_FRAME_FINISH_FRONT/LANDING_DOOR_FRAME_FINISH_FRONT_VALUE as atomic values? Or something else? thanks – David Thielen Nov 21 '20 at 12:48
  • @DavidThielen, if you have a function call in the last step of a path expression e.g. `foo/bar/distinct-values(foobar)` then it is basically `for $bar in foo/bar return distinct-values($bar/foobar)`, see https://www.w3.org/TR/xpath-31/#id-path-operator, so in the end you get the concatenated sequence of all distinct-values, only, given your path example `PROJECT[1]/PROPOSAL[1]/SOLUTION[1]/UNIT[1]`, it seems you select only a single `UNIT` anyway whose distinct-values for the descendant `LANDING_DOOR_FRAME_FINISH_FRONT/LANDING_DOOR_FRAME_FINISH_FRONT_VALUE` are computed. – Martin Honnen Nov 21 '20 at 13:18