Skip to content
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

fn:elements-to-maps: Types #1648

Open
ChristianGruen opened this issue Dec 6, 2024 · 2 comments
Open

fn:elements-to-maps: Types #1648

ChristianGruen opened this issue Dec 6, 2024 · 2 comments
Labels
Editorial Minor typos, wording clarifications, example fixes, etc. XQFO An issue related to Functions and Operators

Comments

@ChristianGruen
Copy link
Contributor

Copied from #1592 (comment):

With regard to types, I would propose to introduce a separate option:

elements-to-maps(
  <value>42</value>,
  { 'types': { 'value': 'number' } }
)

→ { "value": 42 }

I have a preference for strings, as we can prefix them with @. Next, the representation could be identical to the result, which I believe is more intuitive:

elements-to-maps(
  <value count='3'/>
  { 'types': { '@count': 'number' } }
)

→ { "value": { "@count": 3 } }

Of course, we could also have two options (element-types, attribute-types).

@ChristianGruen ChristianGruen added XQFO An issue related to Functions and Operators Editorial Minor typos, wording clarifications, example fixes, etc. labels Dec 6, 2024
@michaelhkay
Copy link
Contributor

I think we have a mechanism for defining the types of values, called XSD validation, and we shouldn't invent another.

@ChristianGruen
Copy link
Contributor Author

One more question, probably stupid enough, due to my XSD ignorance. The example for the simple-plus layout is:

<price currency="USD">23.50</date>

The presented result is:

"price": { "@currency": "USD", "#content": 23.50 } }

The mapping rules say:

If the element has been schema-validated, the types of the items in the atomized value are retained.

Does the example imply that the string value of the price element is of type xs:decimal, due to schema validation?

Would it be possible/reasonable to include an ideally self-contained example that shows how a user may end up with a map that contains numbers? I guess there will be no chance to achieve this for ad-hoc data and without the full XSD machinery?

But I see your point, and I did not consider in my suggestion that we are creating maps (not JSON), which makes the challenge much more complex. I will be happy to close this if no one else jumps in.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Editorial Minor typos, wording clarifications, example fixes, etc. XQFO An issue related to Functions and Operators
Projects
None yet
Development

No branches or pull requests

2 participants