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.Namespace;
07: import net.sf.saxon.om.AttributeCollection;
08: import net.sf.saxon.value.StringValue;
09: import net.sf.saxon.trans.XPathException;
10:
11: import javax.xml.transform.TransformerConfigurationException;
12:
13: /**
14: * An xsl:namespace element in the stylesheet. (XSLT 2.0)
15: */
16:
17: public class XSLNamespace extends XSLStringConstructor {
18:
19: Expression name;
20:
21: public void prepareAttributes() throws XPathException {
22:
23: String nameAtt = null;
24: String selectAtt = null;
25:
26: AttributeCollection atts = getAttributeList();
27:
28: for (int a = 0; a < atts.getLength(); a++) {
29: int nc = atts.getNameCode(a);
30: String f = getNamePool().getClarkName(nc);
31: if (f == StandardNames.NAME) {
32: nameAtt = atts.getValue(a).trim();
33: } else if (f == StandardNames.SELECT) {
34: selectAtt = atts.getValue(a).trim();
35: } else {
36: checkUnknownAttribute(nc);
37: }
38: }
39: if (nameAtt == null) {
40: reportAbsence("name");
41: } else {
42: name = makeAttributeValueTemplate(nameAtt);
43: }
44:
45: if (selectAtt != null) {
46: select = makeExpression(selectAtt);
47: }
48:
49: }
50:
51: public void validate() throws XPathException {
52: checkWithinTemplate();
53: name = typeCheck("name", name);
54: select = typeCheck("select", select);
55: super .validate();
56: }
57:
58: public Expression compile(Executable exec) throws XPathException {
59: Namespace inst = new Namespace(name);
60: compileContent(exec, inst, StringValue.SINGLE_SPACE);
61: ExpressionTool.makeParentReferences(inst);
62: return inst;
63: }
64:
65: }
66:
67: //
68: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
69: // you may not use this file except in compliance with the License. You may obtain a copy of the
70: // License at http://www.mozilla.org/MPL/
71: //
72: // Software distributed under the License is distributed on an "AS IS" basis,
73: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
74: // See the License for the specific language governing rights and limitations under the License.
75: //
76: // The Original Code is: all this file.
77: //
78: // The Initial Developer of the Original Code is Michael H. Kay.
79: //
80: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
81: //
82: // Contributor(s): none.
83: //
|