001: package net.sf.saxon.style;
002:
003: import net.sf.saxon.expr.Expression;
004: import net.sf.saxon.expr.ExpressionTool;
005: import net.sf.saxon.instruct.Executable;
006: import net.sf.saxon.instruct.ValueOf;
007: import net.sf.saxon.om.AttributeCollection;
008: import net.sf.saxon.om.Axis;
009: import net.sf.saxon.om.AxisIterator;
010: import net.sf.saxon.om.Item;
011: import net.sf.saxon.pattern.NodeKindTest;
012: import net.sf.saxon.trans.XPathException;
013: import net.sf.saxon.type.ItemType;
014: import net.sf.saxon.value.StringValue;
015:
016: /**
017: * Handler for xsl:text elements in stylesheet. <BR>
018: */
019:
020: public class XSLText extends XSLStringConstructor {
021:
022: private boolean disable = false;
023: private StringValue value;
024:
025: /**
026: * Determine the type of item returned by this instruction (only relevant if
027: * it is an instruction).
028: * @return the item type returned
029: */
030:
031: protected ItemType getReturnedItemType() {
032: return NodeKindTest.TEXT;
033: }
034:
035: public void prepareAttributes() throws XPathException {
036:
037: String disableAtt = null;
038:
039: AttributeCollection atts = getAttributeList();
040:
041: for (int a = 0; a < atts.getLength(); a++) {
042: int nc = atts.getNameCode(a);
043: String f = getNamePool().getClarkName(nc);
044: if (f == StandardNames.DISABLE_OUTPUT_ESCAPING) {
045: disableAtt = atts.getValue(a).trim();
046: } else {
047: checkUnknownAttribute(nc);
048: }
049: }
050:
051: if (disableAtt != null) {
052: if (disableAtt.equals("yes")) {
053: disable = true;
054: } else if (disableAtt.equals("no")) {
055: disable = false;
056: } else {
057: compileError(
058: "disable-output-escaping attribute must be either 'yes' or 'no'",
059: "XTSE0020");
060: }
061: }
062: }
063:
064: public void validate() throws XPathException {
065: checkWithinTemplate();
066:
067: // 2.0 spec has reverted to the 1.0 rule that xsl:text may not have child elements
068: AxisIterator kids = iterateAxis(Axis.CHILD);
069: value = StringValue.EMPTY_STRING;
070: while (true) {
071: Item child = kids.next();
072: if (child == null) {
073: break;
074: } else if (child instanceof StyleElement) {
075: ((StyleElement) child).compileError(
076: "xsl:text must not contain child elements",
077: "XTSE0010");
078: return;
079: } else {
080: value = StringValue.makeStringValue(child
081: .getStringValueCS());
082: continue;
083: }
084: }
085: super .validate();
086: }
087:
088: public Expression compile(Executable exec) throws XPathException {
089: ValueOf inst = new ValueOf(value, disable, false);
090: //compileContent(exec, inst);
091: ExpressionTool.makeParentReferences(inst);
092: return inst;
093: }
094:
095: }
096:
097: //
098: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
099: // you may not use this file except in compliance with the License. You may obtain a copy of the
100: // License at http://www.mozilla.org/MPL/
101: //
102: // Software distributed under the License is distributed on an "AS IS" basis,
103: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
104: // See the License for the specific language governing rights and limitations under the License.
105: //
106: // The Original Code is: all this file.
107: //
108: // The Initial Developer of the Original Code is Michael H. Kay.
109: //
110: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
111: //
112: // Contributor(s): none.
113: //
|