Debian Codegraph @

net/sf/saxon/style/XSLMapEntry.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.ma.map.MapFunctionSet;
14 import net.sf.saxon.ma.map.MapType;
15 import net.sf.saxon.om.AttributeCollection;
16 import net.sf.saxon.om.AxisInfo;
17 import net.sf.saxon.om.NodeInfo;
18 import net.sf.saxon.trans.XPathException;
19 import net.sf.saxon.tree.iter.AxisIterator;
20 import net.sf.saxon.type.ItemType;
21
22 /**
23 * Handler for xsl:map-entry instructions in an XSLT 3.0 stylesheet. <br>
24 */
25
26 public class XSLMapEntry extends StyleElement {
27
28 Expression key = null;
29 Expression select = null;
30
31 /**
32 * Determine whether this node is an instruction.
33 *
34 * @return true - it is an instruction
35 */
36
37 public boolean isInstruction() {
38 return true;
39 }
40
41 /**
42 * Determine the type of item returned by this instruction (only relevant if
43 * it is an instruction).
44 *
45 * @return the item type returned
46 */
47
48 protected ItemType getReturnedItemType() {
49 return MapType.ANY_MAP_TYPE;
50 }
51
52 /**
53 * Determine whether this type of element is allowed to contain a sequence constructor
54 *
55 * @return true: yes, it may contain a sequence constructor
56 */
57
58 public boolean mayContainSequenceConstructor() {
59 return true;
60 }
61
62 public void prepareAttributes() throws XPathException {
63
64 AttributeCollection atts = getAttributeList();
65
66 String keyAtt = null;
67 String selectAtt = null;
68
69 for (int a = 0; a < atts.getLength(); a++) {
70 String f = atts.getQName(a);
71 if (f.equals("key")) {
72 keyAtt = atts.getValue(a);
73 key = makeExpression(keyAtt, a);
74 } else 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 if (keyAtt == null) {
83 reportAbsence("key");
84 }
85
86 }
87
88 public void validate(ComponentDeclaration decl) throws XPathException {
89 key = typeCheck("key", key);
90 select = typeCheck("select", select);
91 if (select != null) {
92 boolean foundChild = false;
93 AxisIterator kids = iterateAxis(AxisInfo.CHILD);
94 NodeInfo kid;
95 while ((kid = kids.next()) != null) {
96 if (kid instanceof XSLFallback) {
97 // no action;
98 } else {
99 foundChild = true;
100 }
101 }
102 if (foundChild) {
103 String errorCode = "XTSE3280";
104 compileError("An xsl:map-entry element with a select attribute must be empty", errorCode);
105 }
106 }
107 }
108
109 public Expression compile(Compilation exec, ComponentDeclaration decl) throws XPathException {
110 if (select == null) {
111 select = compileSequenceConstructor(exec, decl, false);
112 select = select.simplify();
113 }
114 Expression exp = MapFunctionSet.getInstance().makeFunction("entry", 2).makeFunctionCall(key, select);
115 if (getConfiguration().getBooleanProperty(Feature.STRICT_STREAMABILITY)) {
116 exp = new SequenceInstr(exp);
117 }
118 return exp;
119 }
120
121
122 }