1 package com.icl.saxon.style; 2 import com.icl.saxon.Context; 3 import com.icl.saxon.Controller; 4 import com.icl.saxon.om.Name; 5 import com.icl.saxon.om.NodeInfo; 6 import com.icl.saxon.tree.NodeImpl; 7 import com.icl.saxon.expr.Expression; 8 import com.icl.saxon.output.Outputter; 9 import javax.xml.transform.TransformerException ; 10 import javax.xml.transform.TransformerConfigurationException ; 11 12 16 17 public abstract class XSLStringConstructor extends StyleElement { 18 19 private String stringValue = null; 20 private Expression valueExpression = null; 21 22 26 27 public boolean isInstruction() { 28 return true; 29 } 30 31 35 36 public boolean mayContainTemplateBody() { 37 return true; 38 } 39 40 protected void optimize() throws TransformerConfigurationException { 41 NodeImpl first = (NodeImpl)getFirstChild(); 42 if (first==null) { 43 stringValue = ""; 45 } else { 46 NodeImpl next = (NodeImpl)first.getNextSibling(); 47 if (next==null) { 48 if (first.getNodeType() == NodeInfo.TEXT) { 50 stringValue = first.getStringValue(); 52 } else if (first instanceof XSLValueOf) { 53 XSLValueOf v = (XSLValueOf)first; 55 valueExpression = v.getSelectExpression(); 56 if (v.getDisableOutputEscaping()) { 57 v.compileError("disable-output-escaping is not allowed for a non-text node"); 58 } 59 } 60 } 61 } 62 } 63 64 69 70 public String expandChildren(Context context) throws TransformerException { 71 72 if (stringValue != null) { 73 return stringValue; 74 75 } else if (valueExpression != null) { 76 return valueExpression.evaluateAsString(context); 77 78 } else { 79 Controller c = context.getController(); 80 Outputter old = c.getOutputter(); 81 StringBuffer buffer = new StringBuffer (); 82 c.changeToTextOutputDestination(buffer); 83 processChildren(context); 84 c.resetOutputDestination(old); 85 return buffer.toString(); 86 87 } 88 } 89 90 91 } 92 93 | Popular Tags |