| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 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 |
|
| 24 |
|
| 25 |
|
| 26 |
public class XSLMapEntry extends StyleElement { |
| 27 |
|
| 28 |
Expression key = null; |
| 29 |
Expression select = null; |
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
public boolean isInstruction() { |
| 38 |
return true; |
| 39 |
} |
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
protected ItemType getReturnedItemType() { |
| 49 |
return MapType.ANY_MAP_TYPE; |
| 50 |
} |
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 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 |
|
| 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 |
} |