Debian Codegraph @

net/sf/saxon/style/XSLFork.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.Block;
12 import net.sf.saxon.expr.instruct.Fork;
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 * Handler for xsl:fork elements in XSLT 3.0 stylesheet.
21 */
22
23 public class XSLFork extends StyleElement {
24
25 /**
26 * Determine whether this node is an instruction.
27 *
28 * @return true - it is an instruction
29 */
30
31 public boolean isInstruction() {
32 return true;
33 }
34
35 /**
36 * Determine whether this type of element is allowed to contain a sequence constructor
37 *
38 * @return false: no, it may not contain a sequence constructor
39 */
40
41 public boolean mayContainSequenceConstructor() {
42 return false;
43 }
44
45
46 public void prepareAttributes() throws XPathException {
47
48 AttributeCollection atts = getAttributeList();
49
50 for (int a = 0; a < atts.getLength(); a++) {
51 checkUnknownAttribute(atts.getNodeName(a));
52 }
53 }
54
55
56 public void validate(ComponentDeclaration decl) throws XPathException {
57 AxisIterator kids = iterateAxis(AxisInfo.CHILD);
58 NodeInfo child;
59 int foundGroup = 0;
60 int foundSequence = 0;
61 while ((child = kids.next()) != null) {
62 if (child instanceof XSLSequence) {
63 foundSequence++;
64 } else if (child instanceof XSLForEachGroup) {
65 foundGroup++;
66 } else if (child instanceof XSLFallback) {
67 // no action
68 } else {
69 compileError(child.getDisplayName() + " cannot appear as a child of xsl:fork");
70 }
71 }
72 if (foundGroup > 1) {
73 compileError("xsl:fork contains more than one xsl:for-each-group instruction");
74 }
75 if (foundGroup > 0 && foundSequence > 0) {
76 compileError("Cannot mix xsl:sequence and xsl:for-each-group within xsl:fork");
77 }
78 }
79
80 public Expression compile(Compilation exec, ComponentDeclaration decl) throws XPathException {
81 Expression content = compileSequenceConstructor(exec, decl, true);
82 if (content instanceof Block) {
83 return new Fork(((Block) content).getOperanda());
84 } else {
85 return content;
86 }
87 }
88
89
90 }