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.ValueOf;
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: * A saxon:entity-ref element in the stylesheet. This causes an entity reference
15: * to be output to the XML or HTML output stream. <br>
16: */
17:
18: public class SaxonEntityRef extends StyleElement {
19:
20: String nameAttribute;
21:
22: /**
23: * Determine whether this node is an instruction.
24: * @return true - it is an instruction
25: */
26:
27: public boolean isInstruction() {
28: return true;
29: }
30:
31: public void prepareAttributes() throws XPathException {
32:
33: AttributeCollection atts = getAttributeList();
34:
35: for (int a = 0; a < atts.getLength(); a++) {
36: int nc = atts.getNameCode(a);
37: String f = getNamePool().getClarkName(nc);
38: if (f == StandardNames.NAME) {
39: nameAttribute = atts.getValue(a).trim();
40: } else {
41: checkUnknownAttribute(nc);
42: }
43: }
44:
45: if (nameAttribute == null) {
46: reportAbsence("name");
47: }
48: }
49:
50: public void validate() throws XPathException {
51: checkWithinTemplate();
52: checkEmpty();
53: }
54:
55: public Expression compile(Executable exec) throws XPathException {
56: ValueOf text = new ValueOf(new StringValue(
57: '&' + nameAttribute + ';'), true, false);
58: // try {
59: // text.setSelect(new StringValue('&' + nameAttribute + ';'));
60: // } catch (StaticError err) {
61: // compileError(err);
62: // }
63: ExpressionTool.makeParentReferences(text);
64: return text;
65: }
66:
67: }
68: //
69: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
70: // you may not use this file except in compliance with the License. You may obtain a copy of the
71: // License at http://www.mozilla.org/MPL/
72: //
73: // Software distributed under the License is distributed on an "AS IS" basis,
74: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
75: // See the License for the specific language governing rights and limitations under the License.
76: //
77: // The Original Code is: all this file.
78: //
79: // The Initial Developer of the Original Code is Michael H. Kay.
80: //
81: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
82: //
83: // Contributor(s): none.
84: //
|