001: package net.sf.saxon.style;
002:
003: import net.sf.saxon.expr.Expression;
004: import net.sf.saxon.expr.ExpressionTool;
005: import net.sf.saxon.instruct.Executable;
006: import net.sf.saxon.om.AttributeCollection;
007: import net.sf.saxon.om.Axis;
008: import net.sf.saxon.om.AxisIterator;
009: import net.sf.saxon.om.NodeInfo;
010: import net.sf.saxon.trans.XPathException;
011: import net.sf.saxon.type.ItemType;
012: import net.sf.saxon.type.TypeHierarchy;
013: import net.sf.saxon.value.EmptySequence;
014:
015: /**
016: * An xsl:sequence element in the stylesheet. <br>
017: * The xsl:sequence element takes attributes:<ul>
018: * <li>a mandatory attribute select="expression".</li>
019: * </ul>
020: */
021:
022: public final class XSLSequence extends StyleElement {
023:
024: private Expression select;
025:
026: /**
027: * Determine whether this node is an instruction.
028: * @return true - it is an instruction
029: */
030:
031: public boolean isInstruction() {
032: return true;
033: }
034:
035: /**
036: * Determine the type of item returned by this instruction (only relevant if
037: * it is an instruction).
038: * @return the item type returned
039: */
040:
041: protected ItemType getReturnedItemType() {
042: final TypeHierarchy th = getNamePool().getTypeHierarchy();
043: return select.getItemType(th);
044: }
045:
046: /**
047: * Determine whether this type of element is allowed to contain a template-body
048: * @return true: yes, it may contain a template-body
049: */
050:
051: public boolean mayContainSequenceConstructor() {
052: return false;
053: }
054:
055: /**
056: * Determine whether this type of element is allowed to contain an xsl:fallback
057: * instruction
058: */
059:
060: public boolean mayContainFallback() {
061: return true;
062: }
063:
064: public void prepareAttributes() throws XPathException {
065:
066: String selectAtt = null;
067:
068: AttributeCollection atts = getAttributeList();
069:
070: for (int a = 0; a < atts.getLength(); a++) {
071: int nc = atts.getNameCode(a);
072: String f = getNamePool().getClarkName(nc);
073: if (f == StandardNames.SELECT) {
074: selectAtt = atts.getValue(a);
075: } else {
076: checkUnknownAttribute(nc);
077: }
078: }
079:
080: if (selectAtt != null) {
081: select = makeExpression(selectAtt);
082: } else {
083: reportAbsence(StandardNames.SELECT);
084: select = EmptySequence.getInstance();
085: }
086: }
087:
088: public void validate() throws XPathException {
089: checkWithinTemplate();
090: AxisIterator kids = iterateAxis(Axis.CHILD);
091: while (true) {
092: NodeInfo child = (NodeInfo) kids.next();
093: if (child == null)
094: break;
095: if (!(child instanceof XSLFallback)) {
096: compileError(
097: "The only child node allowed for xsl:sequence is an xsl:fallback instruction",
098: "XTSE0010");
099: break;
100: }
101: }
102: select = typeCheck("select", select);
103: }
104:
105: /**
106: * Mark tail-recursive calls on templates and functions.
107: */
108:
109: public void markTailCalls() {
110: StyleElement last = getLastChildInstruction();
111: if (last != null) {
112: last.markTailCalls();
113: } else if (select != null) {
114: ExpressionTool.markTailFunctionCalls(select);
115: }
116: }
117:
118: public Expression compile(Executable exec) {
119: return select;
120: }
121:
122: }
123:
124: //
125: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
126: // you may not use this file except in compliance with the License. You may obtain a copy of the
127: // License at http://www.mozilla.org/MPL/
128: //
129: // Software distributed under the License is distributed on an "AS IS" basis,
130: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
131: // See the License for the specific language governing rights and limitations under the License.
132: //
133: // The Original Code is: all this file.
134: //
135: // The Initial Developer of the Original Code is Michael H. Kay.
136: //
137: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
138: //
139: // Contributor(s): none.
140: //
|