-
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
XSLT patterns: intersect and except #402
Comments
Isn't XSLT 3.0 the last official W3C XSLT specification? I searched for XSLT 3.1 but couldn't find such specification. Any links would be very useful.
isn't this equivalent to the pattern:
If these are equivalent, then for the second one it is clear that it may match a Maybe the pattern should have been specified as:
Probably a more specific example and explanation would be helpful. |
If I get it right, the semantics of If the behavior in XSLT is changed, does that mean that the rules of the two languages are harmonized? Why does the problem not affect the |
I think they have the same semantics in an XPath expression, it's specifically in the context of a match pattern where this problem arises. |
Sorry, typo. I meant 3.0.
I don't think that's actually a legal pattern.
Yes, that pattern would (I think) have the desired effect (provided the relevant tree is rooted at a document node).
Very good question, and I wish I knew how to do the proof. I have managed to persuade myself that the combination of This is relevant because we're interpreting the pattern |
See also my blog article at https://blog.saxonica.com/mike/2022/05/except-patterns.html This proposes that we create new operators |
I can see the problem, but for my own coding I have learned that desired exceptions in a match pattern should motivate the creation of another template with higher priority to overshadow the one I'm currently writing. In other words, I have personally deprecated the As for |
I would like to propose making an incompatible change to the semantics of XSLT patterns using the "except" and "intersect" operators, so that they have their intuitive meaning.
Consider the pattern
p except appendix//p
. Anyone writing this probably imagines that this will match anyp
element that does not have anappendix
as an ancestor. The intuitive meaning ofA except B
is to match anything that matchesA
unless it also matchesB
.The actual meaning in the XSLT 3.1 specification is that it matches any node
$N
that has an ancestor$A
such that the result of the XPath expression$A//(p except appendix//p)
includes$N
.Consider the XML
The
<p>
element here has an ancestor (the<div>
element) where the result of$A//(p except appendix//p)
includes the<p>
element. So despite having an ancestorappendix
this element matches the patternp except appendix//p
. This is not only a counter-intuitive result, it also makes such patterns useless in practice.Patterns using
intersect
suffer the same problem, though it is much harder to construct a plausible example.Patterns that only use the child or attribute axis, for example
@* except @code
, or* except note
, don't suffer from this problem and will retain the same meaning as in 3.1.The required effect can be achieved by writing
p except p[ancestor::appendix]
. Because the patternp[ancestor::appendix]
is equivalent toappendix//p
, people are very likely to imagine thatp except p[ancestor::appendix]
is equivalent top except appendix//p
.Making any incompatible change to the language semantics should be done only with a very strong justification, but I believe that it is justified in this instance. The existing semantics are not only counter-intuitive, they are also sufficiently useless that it is extremely unlikely anyone has existing working code, other than artificial test cases, that relies on the current semantics.
The text was updated successfully, but these errors were encountered: