1 package net.sf.saxon.style; 2 import net.sf.saxon.expr.Expression; 3 import net.sf.saxon.expr.ExpressionTool; 4 import net.sf.saxon.instruct.Executable; 5 import net.sf.saxon.om.AttributeCollection; 6 import net.sf.saxon.om.Axis; 7 import net.sf.saxon.om.AxisIterator; 8 import net.sf.saxon.om.NodeInfo; 9 import net.sf.saxon.trans.XPathException; 10 import net.sf.saxon.type.ItemType; 11 import net.sf.saxon.value.EmptySequence; 12 13 14 20 21 public final class XSLSequence extends StyleElement { 22 23 private Expression select; 24 25 29 30 public boolean isInstruction() { 31 return true; 32 } 33 34 39 40 protected ItemType getReturnedItemType() { 41 return select.getItemType(); 42 } 43 44 48 49 public boolean mayContainSequenceConstructor() { 50 return false; 51 } 52 53 57 58 public boolean mayContainFallback() { 59 return true; 60 } 61 62 public void prepareAttributes() throws XPathException { 63 64 String selectAtt = null; 65 66 AttributeCollection atts = getAttributeList(); 67 68 for (int a=0; a<atts.getLength(); a++) { 69 int nc = atts.getNameCode(a); 70 String f = getNamePool().getClarkName(nc); 71 if (f==StandardNames.SELECT) { 72 selectAtt = atts.getValue(a); 73 } else { 74 checkUnknownAttribute(nc); 75 } 76 } 77 78 if (selectAtt!=null) { 79 select = makeExpression(selectAtt); 80 } else { 81 reportAbsence(StandardNames.SELECT); 82 select = EmptySequence.getInstance(); 83 } 84 } 85 86 public void validate() throws XPathException { 87 checkWithinTemplate(); 88 AxisIterator kids = iterateAxis(Axis.CHILD); 89 while (true) { 90 NodeInfo child = (NodeInfo)kids.next(); 91 if (child == null) break; 92 if (!(child instanceof XSLFallback)) { 93 compileError("The only child node allowed for xsl:sequence is an xsl:fallback instruction", "XTSE0010"); 94 break; 95 } 96 } 97 select = typeCheck("select", select); 98 } 99 100 103 104 public void markTailCalls() { 105 StyleElement last = getLastChildInstruction(); 106 if (last != null) { 107 last.markTailCalls(); 108 } else if (select != null) { 109 ExpressionTool.markTailFunctionCalls(select); 110 } 111 } 112 113 114 public Expression compile(Executable exec) { 115 return select; 116 } 117 118 } 119 120 | Popular Tags |