KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > icl > saxon > style > XSLWhen


1 package com.icl.saxon.style;
2 import com.icl.saxon.tree.AttributeCollection;
3 import com.icl.saxon.*;
4 import com.icl.saxon.expr.*;
5 import javax.xml.transform.*;
6
7
8 /**
9 * Handler for xsl:when elements in stylesheet.<BR>
10 * The xsl:while element has a mandatory attribute test, a boolean expression.
11 */

12
13 public class XSLWhen extends StyleElement {
14
15     private Expression test;
16
17     public Expression getCondition() {
18         return test;
19     }
20
21     /**
22     * Determine whether this element does any processing after instantiating any children.
23     * This implementation says it doesn't, thus enabling tail recursion.
24     */

25
26     public boolean doesPostProcessing() {
27         return false;
28     }
29
30     public void prepareAttributes() throws TransformerConfigurationException {
31         String JavaDoc testAtt=null;
32
33         StandardNames sn = getStandardNames();
34         AttributeCollection atts = getAttributeList();
35                 
36         for (int a=0; a<atts.getLength(); a++) {
37             int nc = atts.getNameCode(a);
38             int f = nc & 0xfffff;
39             if (f==sn.NAME) {
40                 //
41
} else if (f==sn.TEST) {
42                 testAtt = atts.getValue(a);
43             } else {
44                 checkUnknownAttribute(nc);
45             }
46         }
47         
48         if (testAtt==null) {
49             reportAbsence("test");
50         } else {
51             test = makeExpression(testAtt);
52         }
53     }
54
55     /**
56     * Determine whether this type of element is allowed to contain a template-body
57     * @return true: yes, it may contain a template-body
58     */

59
60     public boolean mayContainTemplateBody() {
61         return true;
62     }
63
64     public void validate() throws TransformerConfigurationException {
65         if (!(getParentNode() instanceof XSLChoose)) {
66             compileError("xsl:when must be immediately within xsl:choose");
67         }
68     }
69
70     public void process(Context context) throws TransformerException
71     {
72         processChildren(context); // the condition is tested from the outer xsl:choose element
73
}
74
75 }
76
77 //
78
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
79
// you may not use this file except in compliance with the License. You may obtain a copy of the
80
// License at http://www.mozilla.org/MPL/
81
//
82
// Software distributed under the License is distributed on an "AS IS" basis,
83
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
84
// See the License for the specific language governing rights and limitations under the License.
85
//
86
// The Original Code is: all this file.
87
//
88
// The Initial Developer of the Original Code is
89
// Michael Kay of International Computers Limited (mhkay@iclway.co.uk).
90
//
91
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
92
//
93
// Contributor(s): none.
94
//
95
Popular Tags