Debian Codegraph @

net/sf/saxon/style/XSLSequence.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.expr.instruct.SequenceInstr;
12 import net.sf.saxon.lib.Feature;
13 import net.sf.saxon.om.AttributeCollection;
14 import net.sf.saxon.om.AxisInfo;
15 import net.sf.saxon.om.NodeInfo;
16 import net.sf.saxon.trans.XPathException;
17 import net.sf.saxon.tree.iter.AxisIterator;
18
19
20 /**
21 * An xsl:sequence element in the stylesheet.
22 */
23
24 public class XSLSequence extends StyleElement {
25
26 private Expression select;
27
28 /**
29 * Determine whether this node is an instruction.
30 *
31 * @return true - it is an instruction
32 */
33
34 public boolean isInstruction() {
35 return true;
36 }
37
38 /**
39 * Determine whether this type of element is allowed to contain a sequence constructor
40 *
41 * @return in XSLT 2.0, false. In XSLT 3.0 true: yes, it may contain a sequence constructor
42 */
43
44 public boolean mayContainSequenceConstructor() {
45 return true;
46 }
47
48 /**
49 * Determine whether this type of element is allowed to contain an xsl:fallback
50 * instruction
51 */
52
53 public boolean mayContainFallback() {
54 return true;
55 }
56
57 public Expression getSelectExpression() {
58 return select;
59 }
60
61 public void setSelectExpression(Expression select) {
62 this.select = select;
63 }
64
65
66 public void prepareAttributes() throws XPathException {
67
68 String selectAtt = null;
69
70 AttributeCollection atts = getAttributeList();
71
72 for (int a = 0; a < atts.getLength(); a++) {
73 String f = atts.getQName(a);
74 if (f.equals("select")) {
75 selectAtt = atts.getValue(a);
76 select = makeExpression(selectAtt, a);
77 } else {
78 checkUnknownAttribute(atts.getNodeName(a));
79 }
80 }
81
82 }
83
84 public void validate(ComponentDeclaration decl) throws XPathException {
85 AxisIterator kids = iterateAxis(AxisInfo.CHILD);
86 NodeInfo child;
87 while ((child = kids.next()) != null) {
88 if (!(child instanceof XSLFallback)) {
89 if (select != null) {
90 compileError("An " + getDisplayName() + " element with a select attribute must be empty", "XTSE3185");
91 }
92 break;
93 }
94 }
95 select = typeCheck("select", select);
96 }
97
98 /*@Nullable*/
99 public Expression compile(Compilation exec, ComponentDeclaration decl) throws XPathException {
100 if (select == null) {
101 select = compileSequenceConstructor(exec, decl, false);
102 }
103 if (getConfiguration().getBooleanProperty(Feature.STRICT_STREAMABILITY)) {
104 select = new SequenceInstr(select);
105 }
106 return select;
107 }
108
109 }
110