-
Notifications
You must be signed in to change notification settings - Fork 17
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Using ?
and ??
in XSLT patterns
#1776
Comments
An example or two to illustrate the utility? |
I've deliberately split the whole subject of recursive-descent transformation of JSON structures into a number of small pieces that can be defined and explained independently, but I think the utility only really becomes apparent when you put them together into worked use cases. I will try to do that synthesis in the form of proposed examples in the spec. A lot of it is driven by "filling the gaps" - these are things we are accustomed to doing when processing XML, which prove difficult to do when processing JSON. Matching things by their "container" context is probably even more important in JSON than in XML, because the things in question don't have names in the way that XML elements do. |
For example, given the JSON:
we might want to match individual movies with a pattern such as
|
Supersedes issue #1026 (effectively a duplicate) |
Working this through, I think this proposal is valuable, but it's not the whole answer. Looking at actual JSON from a live application, I see stuff like this nested about 5 levels deep within the JSON document:
and what we don't yet have is the ability to use the name "selectedOptions" as the primary handle in a match pattern to match the data fragment shown here; and that in turn is because this fragment is not actually an item in the data model. It is an entry in a map. But the proposed "shallow-copy-all" processing mode for maps and arrays in fact decomposes a map into its entries and applies templates to the individual entries, so what we need, and don't yet have, is a clean way of matching map entries with a known key. The logical syntax for this, given the way lookup expressions work, would be And if we want to match by type, given the proposed syntax in PR #1778, we should write |
I propose that the pattern
P1 ? P2
, whereP1
andP2
are patterns, should match any labelled item $L provided that $L matches P2, and$L?..
(that is,($L => label())?parent
) matchesP1
.Similarly, the pattern
P1 ?? P2
, whereP1
andP2
are patterns, should match any labelled item $L provided that $L matches P2, and$L?...
(that is,($L => label())?ancestors()
) matchesP1
.Note that neither the syntax nor the semantics are directly related to the lookup operator in XPath. In particular, P2 is a pattern, not a KeySpecifier. But there is a strong analogy, both with the use of
?
and??
in XPath expressions, and with the use of/
and//
in patterns.The text was updated successfully, but these errors were encountered: