Project

Profile

Help

Bug #5867

closed

Unecessary warning due to out of order match pattern resolution

Added by Michael Ihde almost 2 years ago. Updated over 1 year ago.

Status:
Closed
Priority:
Normal
Assignee:
Category:
Internals
Sprint/Milestone:
-
Start date:
2023-02-02
Due date:
% Done:

100%

Estimated time:
Legacy ID:
Applies to branch:
11, 12, trunk
Fix Committed on Branch:
11, 12, trunk
Fixed in Maintenance Release:
Platforms:
.NET, Java

Description

A template match of the form foo/bar[dangerousPredicate] can evaluate out of order (which is rather cool). But this means it can first evaluate the dangerous predicate against some bar, even if it's parent is not foo, and encounter some error in the dangerous predicate then emit a warning. I believe this warning should not be emitted in such circumstances unless the preceding checks also match (in this case that bar has parent foo). I feel like such out of order warning handling has already been dealt with before but perhaps something was just missed here.

Code to reproduce the warning running JDK 11:

import java.io.StringReader;
import javax.xml.transform.stream.StreamSource;
import net.sf.saxon.s9api.Processor;
import net.sf.saxon.s9api.SaxonApiException;
import net.sf.saxon.s9api.Xslt30Transformer;
public class SaxonTest {
	static final String TRANSFORM_DOC = "" //
	+ "<xsl:transform version=\"3.0\" xmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" xmlns:xs=\"http://www.w3.org/2001/XMLSchema\" xmlns:map=\"http://www.w3.org/2005/xpath-functions/map\">" //
	+ "    <xsl:variable name=\"myMap\" as=\"map(xs:string, xs:string)\"><xsl:map/></xsl:variable>" //
	+ "    <xsl:template match=\"foo/bar[map:contains($myMap, @key)]\"/>" //
	+ "</xsl:transform>"; //

	static final String XML_DOC = "<bar/>";

	public static void main(String[] args) throws SaxonApiException {
		Processor processor = new Processor(false);
		try (StringReader xsltIn = new StringReader(TRANSFORM_DOC); StringReader xmlIn = new StringReader(XML_DOC);) {
			Xslt30Transformer transformer = processor.newXsltCompiler().compile(new StreamSource(xsltIn)).load30();
			transformer.applyTemplates(new StreamSource(xmlIn), processor.newSerializer(System.out));
		}
	}
}

Emits this warning:

Warning at char 7 in xsl:template/@match on line 1 column 328 
  XPTY0004  An error occurred matching pattern
  {element(Q{}bar)[Q{http://www.w3.org/2005/xpath-functions/map}contains($myMap,
  atomizeSingleton(attribute::attribute(Q{}key)))]}: An empty sequence is not allowed as the
  second argument of map:contains()

Please register to edit this issue

Also available in: Atom PDF