Debian Codegraph @

net/sf/saxon/style/XSLBreak.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.instruct.BreakInstr;
11 import net.sf.saxon.expr.Expression;
12 import net.sf.saxon.expr.instruct.Block;
13 import net.sf.saxon.om.AttributeCollection;
14 import net.sf.saxon.om.AxisInfo;
15 import net.sf.saxon.trans.XPathException;
16
17 /**
18 * A xsl:break element in the stylesheet
19 */
20
21 public class XSLBreak extends XSLBreakOrContinue {
22
23 private Expression select;
24
25 public void prepareAttributes() throws XPathException {
26
27 String selectAtt = null;
28
29 AttributeCollection atts = getAttributeList();
30
31 for (int a = 0; a < atts.getLength(); a++) {
32 String f = atts.getQName(a);
33 if (f.equals("select")) {
34 selectAtt = atts.getValue(a);
35 select = makeExpression(selectAtt, a);
36 } else {
37 checkUnknownAttribute(atts.getNodeName(a));
38 }
39 }
40
41 }
42
43 /**
44 * Determine whether this type of element is allowed to contain a sequence constructor
45 *
46 * @return true if this instruction is allowed to contain a sequence constructor
47 */
48
49 protected boolean mayContainSequenceConstructor() {
50 return true;
51 }
52
53 /**
54 * Check that the stylesheet element is valid. This is called once for each element, after
55 * the entire tree has been built. As well as validation, it can perform first-time
56 * initialisation. The default implementation does nothing; it is normally overriden
57 * in subclasses.
58 *
59 * @param decl
60 */
61
62 public void validate(ComponentDeclaration decl) throws XPathException {
63 validatePosition();
64 if (xslIterate == null) {
65 compileError(getDisplayName() + " must be a descendant of an xsl:iterate instruction", "XTSE3120"); //XTSE0010
66 }
67 if (select != null && iterateAxis(AxisInfo.CHILD).next() != null) {
68 compileError("An xsl:break element with a select attribute must be empty", "XTSE3125");
69 }
70 select = typeCheck("select", select);
71 }
72
73
74 public Expression compile(Compilation exec, ComponentDeclaration decl) throws XPathException {
75 // xsl:break containing a sequence constructor is compiled into a call on the sequence constructor, then
76 // the break instruction
77 Expression val = select;
78 if (val == null) {
79 val = compileSequenceConstructor(exec, decl, false);
80 }
81
82 Expression brake = new BreakInstr();
83 brake.setRetainedStaticContext(makeRetainedStaticContext());
84 return Block.makeBlock(val, brake);
85 }
86
87 }