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