01: package net.sf.saxon.style;
02:
03: import net.sf.saxon.expr.Expression;
04: import net.sf.saxon.expr.ExpressionTool;
05: import net.sf.saxon.instruct.Executable;
06: import net.sf.saxon.instruct.While;
07: import net.sf.saxon.om.AttributeCollection;
08: import net.sf.saxon.om.Axis;
09: import net.sf.saxon.trans.XPathException;
10: import net.sf.saxon.value.EmptySequence;
11:
12: /**
13: * Handler for saxon:while elements in stylesheet.
14: * The saxon:while element has a mandatory attribute test, a boolean expression.
15: * The content is output repeatedly so long as the test condition is true.
16: */
17:
18: public class SaxonWhile extends StyleElement {
19:
20: private Expression test;
21:
22: /**
23: * Determine whether this node is an instruction.
24: * @return true - it is an instruction
25: */
26:
27: public boolean isInstruction() {
28: return true;
29: }
30:
31: /**
32: * Determine whether this type of element is allowed to contain a template-body
33: * @return true: yes, it may contain a template-body
34: */
35:
36: public boolean mayContainSequenceConstructor() {
37: return true;
38: }
39:
40: public void prepareAttributes() throws XPathException {
41:
42: String testAtt = null;
43:
44: AttributeCollection atts = getAttributeList();
45:
46: for (int a = 0; a < atts.getLength(); a++) {
47: int nc = atts.getNameCode(a);
48: String f = getNamePool().getClarkName(nc);
49: if (f == StandardNames.TEST) {
50: testAtt = atts.getValue(a);
51: } else {
52: checkUnknownAttribute(nc);
53: }
54: }
55:
56: if (testAtt == null) {
57: reportAbsence("test");
58: return;
59: }
60: test = makeExpression(testAtt);
61: }
62:
63: public void validate() throws XPathException {
64: checkWithinTemplate();
65: test = typeCheck("test", test);
66: }
67:
68: public Expression compile(Executable exec) throws XPathException {
69: Expression action = compileSequenceConstructor(exec,
70: iterateAxis(Axis.CHILD), true);
71: if (action == null) {
72: action = EmptySequence.getInstance();
73: }
74: While w = new While(test, action);
75: ExpressionTool.makeParentReferences(w);
76: return w;
77: }
78:
79: }
80:
81: //
82: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
83: // you may not use this file except in compliance with the License. You may obtain a copy of the
84: // License at http://www.mozilla.org/MPL/
85: //
86: // Software distributed under the License is distributed on an "AS IS" basis,
87: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
88: // See the License for the specific language governing rights and limitations under the License.
89: //
90: // The Original Code is: all this file.
91: //
92: // The Initial Developer of the Original Code is Michael H. Kay.
93: //
94: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
95: //
96: // Contributor(s): none.
97: //
|