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

XSLT: keys as maps #1619

Open
michaelhkay opened this issue Nov 29, 2024 · 1 comment · May be fixed by #1622
Open

XSLT: keys as maps #1619

michaelhkay opened this issue Nov 29, 2024 · 1 comment · May be fixed by #1622
Labels
Feature A change that introduces a new feature Tests Needed Tests need to be written or merged XSLT An issue related to XSLT

Comments

@michaelhkay
Copy link
Contributor

michaelhkay commented Nov 29, 2024

I propose an XSLT function map-for-key('keyname', $root) which returns a map $M having the property that map:get($M, $key) returns the value of key('keyname', $key, $root).

This enables XSLT keys to be exploited in new ways: for example it becomes easy to merge the indexes for multiple documents, or to iterate over all the keys in a document.

These benefits can already be obtained by scrapping keys entirely and building maps instead; but keys do have some benefits (like remaining implicitly associated with particular documents, and being "more declarative") and if you've got a legacy application that makes extensive use of keys, this function gives you a bridging capability.

There are a few edge cases that will need ironing out, for example keys allow matching using a collation, which maps don't. (And the spec of xsl:key, now I come to think of it, says nothing about comparing date/time values in different timezones; I don't expect anyone has ever tried.)

@michaelhkay michaelhkay added XSLT An issue related to XSLT Feature A change that introduces a new feature Tests Needed Tests need to be written or merged labels Nov 29, 2024
@michaelhkay
Copy link
Contributor Author

Separate but related: we should align keys with maps by using fn:atomic-equal() for comparisons rather than eq, at least in the case of numerics, to get rid of the non-transitivity problems. Timezones need more thought.

@michaelhkay michaelhkay linked a pull request Nov 29, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Feature A change that introduces a new feature Tests Needed Tests need to be written or merged XSLT An issue related to XSLT
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant