KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sf > saxon > style > XSLSequence


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 /**
15  * An xsl:sequence element in the stylesheet. <br>
16  * The xsl:sequence element takes attributes:<ul>
17  * <li>a mandatory attribute select="expression".</li>
18  * </ul>
19  */

20
21 public final class XSLSequence extends StyleElement {
22
23     private Expression select;
24
25     /**
26     * Determine whether this node is an instruction.
27     * @return true - it is an instruction
28     */

29
30     public boolean isInstruction() {
31         return true;
32     }
33
34     /**
35      * Determine the type of item returned by this instruction (only relevant if
36      * it is an instruction).
37      * @return the item type returned
38      */

39
40     protected ItemType getReturnedItemType() {
41         return select.getItemType();
42     }
43
44     /**
45     * Determine whether this type of element is allowed to contain a template-body
46     * @return true: yes, it may contain a template-body
47     */

48
49     public boolean mayContainSequenceConstructor() {
50         return false;
51     }
52
53     /**
54     * Determine whether this type of element is allowed to contain an xsl:fallback
55     * instruction
56     */

57
58     public boolean mayContainFallback() {
59         return true;
60     }
61
62     public void prepareAttributes() throws XPathException {
63
64         String JavaDoc 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 JavaDoc 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     /**
101     * Mark tail-recursive calls on templates and functions.
102     */

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 //
121
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
122
// you may not use this file except in compliance with the License. You may obtain a copy of the
123
// License at http://www.mozilla.org/MPL/
124
//
125
// Software distributed under the License is distributed on an "AS IS" basis,
126
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
127
// See the License for the specific language governing rights and limitations under the License.
128
//
129
// The Original Code is: all this file.
130
//
131
// The Initial Developer of the Original Code is Michael H. Kay.
132
//
133
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
134
//
135
// Contributor(s): none.
136
//
137
Popular Tags