KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.icl.saxon.style;
2 import com.icl.saxon.tree.AttributeCollection;
3 import com.icl.saxon.*;
4 import com.icl.saxon.om.*;
5 import com.icl.saxon.expr.*;
6 import com.icl.saxon.output.Outputter;
7 import javax.xml.transform.*;
8
9
10 /**
11 * An xsl:copy-of element in the stylesheet.<BR>
12 * The xsl:copy-of element takes:<ul>
13 * <li>an optional attribute select="pattern", defaulting to "." (the current element).</li>
14 * </ul>
15 */

16
17 public class XSLCopyOf extends StyleElement {
18
19     Expression select;
20
21     /**
22     * Determine whether this node is an instruction.
23     * @return true - it is an instruction
24     */

25
26     public boolean isInstruction() {
27         return true;
28     }
29
30
31     public void prepareAttributes() throws TransformerConfigurationException {
32
33         StandardNames sn = getStandardNames();
34         AttributeCollection atts = getAttributeList();
35         String selectAtt = null;
36         
37         for (int a=0; a<atts.getLength(); a++) {
38             int nc = atts.getNameCode(a);
39             int f = nc & 0xfffff;
40             if (f==sn.SELECT) {
41                 selectAtt = atts.getValue(a);
42             } else {
43                 checkUnknownAttribute(nc);
44             }
45         }
46
47         if (selectAtt!=null) {
48             select = makeExpression(selectAtt);
49         } else {
50             reportAbsence("select");
51         }
52     }
53
54     public void validate() throws TransformerConfigurationException {
55         checkWithinTemplate();
56         checkEmpty();
57     }
58
59     public void process(Context context) throws TransformerException
60     {
61         
62         if (select instanceof NodeSetExpression) {
63             copyNodeSet(select, context);
64         } else {
65             Value value = select.evaluate(context);
66             if (value instanceof FragmentValue) {
67                 ((FragmentValue)value).copy(context.getOutputter());
68                 
69             } else if (value instanceof TextFragmentValue) {
70                 ((TextFragmentValue)value).copy(context.getOutputter());
71                 
72             } else if (value instanceof NodeSetValue) {
73                 copyNodeSet((NodeSetValue)value, context);
74                 
75             } else {
76                 context.getOutputter().writeContent(value.asString());
77             }
78         }
79     }
80     
81     private void copyNodeSet(Expression nodeSet, Context c) throws TransformerException {
82         Outputter out = c.getOutputter();
83         NodeEnumeration enum = nodeSet.enumerate(c, true);
84         while (enum.hasMoreElements()) {
85             NodeInfo node = enum.nextElement();
86             node.copy(out);
87         }
88     }
89
90 }
91
92 //
93
// The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
94
// you may not use this file except in compliance with the License. You may obtain a copy of the
95
// License at http://www.mozilla.org/MPL/
96
//
97
// Software distributed under the License is distributed on an "AS IS" basis,
98
// WITHOUT WARRANTY OF ANY KIND, either express or implied.
99
// See the License for the specific language governing rights and limitations under the License.
100
//
101
// The Original Code is: all this file.
102
//
103
// The Initial Developer of the Original Code is
104
// Michael Kay of International Computers Limited (mhkay@iclway.co.uk).
105
//
106
// Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
107
//
108
// Contributor(s): none.
109
//
110
Popular Tags