1 package net.sf.saxon.style; 2 3 import net.sf.saxon.expr.Expression; 4 import net.sf.saxon.instruct.Executable; 5 import net.sf.saxon.instruct.SimpleContentConstructor; 6 import net.sf.saxon.instruct.SimpleNodeConstructor; 7 import net.sf.saxon.om.Axis; 8 import net.sf.saxon.om.AxisIterator; 9 import net.sf.saxon.om.NodeInfo; 10 import net.sf.saxon.trans.StaticError; 11 import net.sf.saxon.trans.XPathException; 12 import net.sf.saxon.type.Type; 13 import net.sf.saxon.value.StringValue; 14 15 19 20 public abstract class XSLStringConstructor extends StyleElement { 21 22 protected Expression select = null; 24 25 30 31 public boolean isInstruction() { 32 return true; 33 } 34 35 40 41 public boolean mayContainSequenceConstructor() { 42 return true; 43 } 44 45 public void validate() throws XPathException { 46 if (select != null && hasChildNodes()) { 47 compileError("An " + getDisplayName() + " element with a select attribute must be empty"); 48 } 49 AxisIterator kids = iterateAxis(Axis.CHILD); 50 NodeInfo first = (NodeInfo)kids.next(); 51 if (select == null) { 52 if (first == null) { 53 select = StringValue.EMPTY_STRING; 56 } else { 57 if (kids.next() == null) { 58 if (first.getNodeKind() == Type.TEXT) { 60 select = StringValue.makeStringValue(first.getStringValueCS()); 62 } 63 } 64 } 65 } 66 } 67 68 protected void compileContent(Executable exec, SimpleNodeConstructor inst, Expression separator) throws XPathException { 69 if (separator == null) { 70 separator = StringValue.SINGLE_SPACE; 71 } 72 try { 73 if (select != null) { 74 inst.setSelect(new SimpleContentConstructor(select, separator).simplify(getStaticContext())); 75 } else { 76 Expression content = compileSequenceConstructor(exec, iterateAxis(Axis.CHILD), true); 77 inst.setSelect(new SimpleContentConstructor(content, separator).simplify(getStaticContext())); 78 } 79 } catch (StaticError err) { 80 compileError(err); 81 } 82 } 83 84 85 } 86 87 | Popular Tags |