Debian Codegraph @

net/sf/saxon/style/XSLOnCompletion.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
6 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
7
8 package net.sf.saxon.style;
9
10 import net.sf.saxon.expr.Expression;
11 import net.sf.saxon.om.AttributeCollection;
12 import net.sf.saxon.om.AxisInfo;
13 import net.sf.saxon.pattern.NodeKindTest;
14 import net.sf.saxon.trans.XPathException;
15
16 /**
17 * An xsl:on-completion element in the stylesheet (XSLT 3.0). <br>
18 */
19
20 public class XSLOnCompletion extends StyleElement {
21
22 private Expression select;
23
24 /**
25 * Determine whether this node is an instruction.
26 *
27 * @return true - it is an instruction
28 */
29
30 public boolean isInstruction() {
31 return true;
32 }
33
34 /**
35 * Determine whether this type of element is allowed to contain a sequence constructor
36 *
37 * @return true: yes, it may contain a sequence constructor
38 */
39
40 public boolean mayContainSequenceConstructor() {
41 return true;
42 }
43
44 public void prepareAttributes() throws XPathException {
45 String selectAtt = null;
46
47 AttributeCollection atts = getAttributeList();
48
49 for (int a = 0; a < atts.getLength(); a++) {
50 String f = atts.getQName(a);
51 if (f.equals("select")) {
52 selectAtt = atts.getValue(a);
53 select = makeExpression(selectAtt, a);
54 } else {
55 checkUnknownAttribute(atts.getNodeName(a));
56 }
57 }
58
59 }
60
61 public void validate(ComponentDeclaration decl) throws XPathException {
62 StyleElement parent = (StyleElement) getParent();
63 if (!(parent instanceof XSLIterate)) {
64 compileError("xsl:on-completion is not allowed as a child of " + parent.getDisplayName(), "XTSE0010");
65 }
66 // See W3C bug 24179, which changes the position of xsl:on-completion within xsl:iterate
67 // For the time being we allow it anywhere, and give a warning if it is in the wrong place
68 iterateAxis(AxisInfo.PRECEDING_SIBLING, NodeKindTest.ELEMENT).forEach(sib -> {
69 if (!(sib instanceof XSLFallback || sib instanceof XSLLocalParam)) {
70 compileWarning("The rules for xsl:iterate have changed (see W3C bug 24179): " +
71 "xsl:on-completion must now be the first child of xsl:iterate after the xsl:param elements", "XTSE0010");
72 }
73 });
74
75 if (select != null && iterateAxis(AxisInfo.CHILD).next() != null) {
76 compileError("An xsl:on-completion element with a select attribute must be empty", "XTSE3125");
77 }
78 select = typeCheck("select", select);
79 }
80
81 public Expression compile(Compilation exec, ComponentDeclaration decl) throws XPathException {
82 if (select == null) {
83 return compileSequenceConstructor(exec, decl, true);
84 } else {
85 return select;
86 }
87 }
88
89
90 }