| 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.Literal; |
| 12 |
import net.sf.saxon.expr.StaticProperty; |
| 13 |
import net.sf.saxon.expr.instruct.SequenceInstr; |
| 14 |
import net.sf.saxon.expr.parser.RoleDiagnostic; |
| 15 |
import net.sf.saxon.expr.parser.TypeChecker; |
| 16 |
import net.sf.saxon.lib.Feature; |
| 17 |
import net.sf.saxon.ma.map.HashTrieMap; |
| 18 |
import net.sf.saxon.ma.map.MapFunctionSet; |
| 19 |
import net.sf.saxon.ma.map.MapType; |
| 20 |
import net.sf.saxon.om.AttributeCollection; |
| 21 |
import net.sf.saxon.trans.XPathException; |
| 22 |
import net.sf.saxon.type.ItemType; |
| 23 |
import net.sf.saxon.value.SequenceType; |
| 24 |
import net.sf.saxon.value.StringValue; |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
public class XSLMap extends StyleElement { |
| 31 |
|
| 32 |
Expression select = null; |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public boolean isInstruction() { |
| 41 |
return true; |
| 42 |
} |
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
protected ItemType getReturnedItemType() { |
| 52 |
return MapType.ANY_MAP_TYPE; |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
public boolean mayContainSequenceConstructor() { |
| 62 |
return true; |
| 63 |
} |
| 64 |
|
| 65 |
public void prepareAttributes() throws XPathException { |
| 66 |
AttributeCollection atts = getAttributeList(); |
| 67 |
|
| 68 |
for (int a = 0; a < atts.getLength(); a++) { |
| 69 |
String f = atts.getQName(a); |
| 70 |
checkUnknownAttribute(atts.getNodeName(a)); |
| 71 |
} |
| 72 |
} |
| 73 |
|
| 74 |
public Expression compile(Compilation exec, ComponentDeclaration decl) throws XPathException { |
| 75 |
select = compileSequenceConstructor(exec, decl, false); |
| 76 |
select = select.simplify(); |
| 77 |
|
| 78 |
TypeChecker tc = getConfiguration().getTypeChecker(false); |
| 79 |
RoleDiagnostic role = new RoleDiagnostic(RoleDiagnostic.MISC, "xsl:map sequence constructor", 0); |
| 80 |
role.setErrorCode("XTTE3375"); |
| 81 |
select = tc.staticTypeCheck( |
| 82 |
select, |
| 83 |
SequenceType.makeSequenceType(MapType.ANY_MAP_TYPE, StaticProperty.ALLOWS_ZERO_OR_MORE), |
| 84 |
role, makeExpressionVisitor()); |
| 85 |
HashTrieMap options = new HashTrieMap(); |
| 86 |
options.initialPut(new StringValue("duplicates"), new StringValue("reject")); |
| 87 |
options.initialPut(new StringValue("duplicates-error-code"), new StringValue("XTDE3365")); |
| 88 |
Expression exp = MapFunctionSet.getInstance().makeFunction("merge", 2).makeFunctionCall(select, Literal.makeLiteral(options)); |
| 89 |
if (getConfiguration().getBooleanProperty(Feature.STRICT_STREAMABILITY)) { |
| 90 |
exp = new SequenceInstr(exp); |
| 91 |
} |
| 92 |
return exp; |
| 93 |
} |
| 94 |
|
| 95 |
} |