Debian Codegraph @

net/sf/saxon/style/XSLNextMatch.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.NextMatch;
12 import net.sf.saxon.om.AttributeCollection;
13 import net.sf.saxon.om.AxisInfo;
14 import net.sf.saxon.om.NodeInfo;
15 import net.sf.saxon.trans.XPathException;
16 import net.sf.saxon.tree.iter.AxisIterator;
17 import net.sf.saxon.type.Type;
18 import net.sf.saxon.value.Whitespace;
19
20 /**
21 * An xsl:next-match element in the stylesheet
22 */
23
24 public class XSLNextMatch extends StyleElement {
25
26 private boolean useTailRecursion = false;
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 an xsl:fallback
40 * instruction
41 */
42
43 public boolean mayContainFallback() {
44 return true;
45 }
46
47 public void prepareAttributes() throws XPathException {
48
49 AttributeCollection atts = getAttributeList();
50
51 for (int a = 0; a < atts.getLength(); a++) {
52 checkUnknownAttribute(atts.getNodeName(a));
53 }
54 }
55
56 public void validate(ComponentDeclaration decl) throws XPathException {
57 AxisIterator kids = iterateAxis(AxisInfo.CHILD);
58 while (true) {
59 NodeInfo child = kids.next();
60 if (child == null) {
61 break;
62 }
63 if (child instanceof XSLWithParam || child instanceof XSLFallback) {
64 // OK;
65 } else if (child.getNodeKind() == Type.TEXT) {
66 // with xml:space=preserve, white space nodes may still be there
67 if (!Whitespace.isWhite(child.getStringValueCS())) {
68 compileError("No character data is allowed within xsl:next-match", "XTSE0010");
69 }
70 } else {
71 compileError("Child element " + child.getDisplayName() +
72 " is not allowed as a child of xsl:next-match", "XTSE0010");
73 }
74 }
75
76 }
77
78
79 /**
80 * Mark tail-recursive calls on templates and functions.
81 * For most instructions, this does nothing.
82 */
83
84 protected boolean markTailCalls() {
85 useTailRecursion = true;
86 return true;
87 }
88
89 /*@NotNull*/
90 public Expression compile(Compilation exec, ComponentDeclaration decl) throws XPathException {
91 NextMatch inst = new NextMatch(useTailRecursion);
92 inst.setLocation(allocateLocation());
93 inst.setActualParams(getWithParamInstructions(inst, exec, decl, false));
94 inst.setTunnelParams(getWithParamInstructions(inst, exec, decl, true));
95 return inst;
96 }
97
98 }
99