Debian Codegraph @

net/sf/saxon/style/XSLApplyImports.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.ApplyImports;
12 import net.sf.saxon.expr.instruct.WithParam;
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 import net.sf.saxon.tree.linked.NodeImpl;
19 import net.sf.saxon.type.Type;
20 import net.sf.saxon.value.Whitespace;
21
22 /**
23 * An xsl:apply-imports element in the stylesheet
24 */
25
26 public class XSLApplyImports extends StyleElement {
27
28
29 /**
30 * Determine whether this node is an instruction.
31 *
32 * @return true - it is an instruction
33 */
34
35 public boolean isInstruction() {
36 return true;
37 }
38
39 public void prepareAttributes() throws XPathException {
40
41 AttributeCollection atts = getAttributeList();
42
43 for (int a = 0; a < atts.getLength(); a++) {
44 checkUnknownAttribute(atts.getNodeName(a));
45 }
46 }
47
48 public void validate(ComponentDeclaration decl) throws XPathException {
49 //checkWithinTemplate();
50 AxisIterator kids = iterateAxis(AxisInfo.CHILD);
51 while (true) {
52 NodeInfo child = kids.next();
53 if (child == null) {
54 break;
55 }
56 if (child instanceof XSLWithParam) {
57 // OK;
58 } else if (child.getNodeKind() == Type.TEXT) {
59 // with xml:space=preserve, white space nodes may still be there
60 if (!Whitespace.isWhite(child.getStringValueCS())) {
61 compileError("No character data is allowed within xsl:apply-imports", "XTSE0010");
62 }
63 } else {
64 compileError("Child element " + child.getDisplayName() +
65 " is not allowed as a child of xsl:apply-imports", "XTSE0010");
66 }
67 }
68
69 NodeImpl parent = getParent();
70 while (parent != null) {
71 if (parent instanceof XSLOverride) {
72 compileError("xsl:apply-imports cannot be used in a template rule declared within xsl:override", "XTSE3460");
73 }
74 parent = parent.getParent();
75 }
76 }
77
78 /*@NotNull*/
79 public Expression compile(Compilation exec, ComponentDeclaration decl) throws XPathException {
80 ApplyImports inst = new ApplyImports();
81 WithParam[] nonTunnels = getWithParamInstructions(inst, exec, decl, false);
82 WithParam[] tunnels = getWithParamInstructions(inst, exec, decl, true);
83 inst.setActualParams(nonTunnels);
84 inst.setTunnelParams(tunnels);
85 return inst;
86 }
87
88 }
89