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.Assign;
06: import net.sf.saxon.instruct.Executable;
07: import net.sf.saxon.trans.XPathException;
08:
09: /**
10: * saxon:assign element in stylesheet.
11: * The saxon:assign element has mandatory attribute name and optional attribute expr.
12: * It also allows xsl:extension-element-prefixes etc.
13: */
14:
15: public class SaxonAssign extends XSLGeneralVariable {
16:
17: private XSLVariableDeclaration declaration; // link to the variable declaration
18: private Assign instruction = new Assign();
19:
20: /**
21: * Determine whether this node is an instruction.
22: * @return true - it is an instruction
23: */
24:
25: public boolean isInstruction() {
26: return true;
27: }
28:
29: public boolean isAssignable() { // this variable is assignable by definition
30: return true;
31: }
32:
33: protected boolean allowsAsAttribute() {
34: return false;
35: }
36:
37: public void validate() throws XPathException {
38: checkWithinTemplate();
39: super .validate();
40: try {
41: declaration = bindVariable(getVariableFingerprint());
42: declaration.registerReference(instruction);
43: requiredType = declaration.getRequiredType();
44: } catch (XPathException err) {
45: // variable not declared
46: compileError(err.getMessage());
47: return;
48: }
49: if (!declaration.isAssignable()) {
50: compileError("Variable " + getVariableName()
51: + " is not marked as assignable");
52: }
53: if (!declaration.isGlobal()) {
54: compileError("saxon:assign now works only with global variables");
55: }
56: }
57:
58: public Expression compile(Executable exec) throws XPathException {
59: initializeInstruction(exec, instruction);
60: ExpressionTool.makeParentReferences(instruction);
61: return instruction;
62: }
63:
64: }
65:
66: //
67: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
68: // you may not use this file except in compliance with the License. You may obtain a copy of the
69: // License at http://www.mozilla.org/MPL/
70: //
71: // Software distributed under the License is distributed on an "AS IS" basis,
72: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
73: // See the License for the specific language governing rights and limitations under the License.
74: //
75: // The Original Code is: all this file.
76: //
77: // The Initial Developer of the Original Code is Michael H. Kay.
78: //
79: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
80: //
81: // Contributor(s): none.
82: //
|