KickJava   Java API By Example, From Geeks To Geeks.

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


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:if elements in stylesheet.<BR>
10 * The xsl:if element has a mandatory attribute test, a boolean expression.
11 * The content is output if the test condition is true.
12 */

13
14 public class XSLIf extends StyleElement {
15
16     private Expression test;
17
18     /**
19     * Determine whether this node is an instruction.
20     * @return true - it is an instruction
21     */

22
23     public boolean isInstruction() {
24         return true;
25     }
26
27     /**
28     * Determine whether this element does any processing after instantiating any children.
29     * This implementation says it doesn't, thus enabling tail recursion.
30     */

31
32     public boolean doesPostProcessing() {
33         return false;
34     }
35
36     /**
37     * Determine whether this type of element is allowed to contain a template-body
38     * @return true: yes, it may contain a template-body
39     */

40
41     public boolean mayContainTemplateBody() {
42         return true;
43     }
44
45     public void prepareAttributes() throws TransformerConfigurationException {
46         
47         String JavaDoc testAtt=null;
48
49         StandardNames sn = getStandardNames();
50         AttributeCollection atts = getAttributeList();
51                 
52         for (int a=0; a<atts.getLength(); a++) {
53             int nc = atts.getNameCode(a);
54             int f = nc & 0xfffff;
55             if (f==sn.NAME) {
56                 //
57
} else if (f==sn.TEST) {
58                 testAtt = atts.getValue(a);
59             } else {
60                 checkUnknownAttribute(nc);
61             }
62         }
63         
64         if (testAtt==null) {
65             reportAbsence("test");
66         } else {
67             test = makeExpression(testAtt);
68         }
69     }
70
71     public void validate() throws TransformerConfigurationException {
72         checkWithinTemplate();
73     }
74
75     public void process(Context context) throws TransformerException
76     {
77         if (test.evaluateAsBoolean(context)) {
78             processChildren(context);
79         }
80     }
81
82 }
83 //
84
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
85
// you may not use this file except in compliance with the License. You may obtain a copy of the
86
// License at http://www.mozilla.org/MPL/
87
//
88
// Software distributed under the License is distributed on an "AS IS" basis,
89
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
90
// See the License for the specific language governing rights and limitations under the License.
91
//
92
// The Original Code is: all this file.
93
//
94
// The Initial Developer of the Original Code is
95
// Michael Kay of International Computers Limited (mhkay@iclway.co.uk).
96
//
97
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
98
//
99
// Contributor(s): none.
100
//
101
Popular Tags