1 package net.sf.saxon.style; 2 import net.sf.saxon.expr.Expression; 3 import net.sf.saxon.expr.ExpressionTool; 4 import net.sf.saxon.instruct.Block; 5 import net.sf.saxon.instruct.Executable; 6 import net.sf.saxon.instruct.Message; 7 import net.sf.saxon.om.AttributeCollection; 8 import net.sf.saxon.om.Axis; 9 import net.sf.saxon.value.StringValue; 10 import net.sf.saxon.trans.XPathException; 11 12 import javax.xml.transform.TransformerConfigurationException ; 13 14 15 18 19 public final class XSLMessage extends StyleElement { 20 21 private Expression terminate = null; 22 private Expression select = null; 23 24 28 29 public boolean isInstruction() { 30 return true; 31 } 32 33 37 38 public boolean mayContainSequenceConstructor() { 39 return true; 40 } 41 42 public void prepareAttributes() throws XPathException { 43 44 String terminateAtt = null; 45 String selectAtt = null; 46 AttributeCollection atts = getAttributeList(); 47 48 for (int a=0; a<atts.getLength(); a++) { 49 int nc = atts.getNameCode(a); 50 String f = getNamePool().getClarkName(nc); 51 if (f == StandardNames.TERMINATE) { 52 terminateAtt = atts.getValue(a).trim(); 53 } else if (f == StandardNames.SELECT) { 54 selectAtt = atts.getValue(a); 55 56 } else { 57 checkUnknownAttribute(nc); 58 } 59 } 60 if (selectAtt!=null) { 61 select = makeExpression(selectAtt); 62 } 63 64 65 if (terminateAtt==null) { 66 terminateAtt = "no"; 67 } 68 69 terminate = makeAttributeValueTemplate(terminateAtt); 70 if (terminate instanceof StringValue) { 71 String t = ((StringValue)terminate).getStringValue(); 72 if (!(t.equals("yes") || t.equals("no"))) { 73 compileError("terminate must be 'yes' or 'no'", "XTSE0020"); 74 } 75 } 76 } 77 78 public void validate() throws XPathException { 79 if (!(getParent() instanceof XSLFunction)) { 80 checkWithinTemplate(); 81 } 82 select = typeCheck("select", select); 83 terminate = typeCheck("terminate", terminate); 84 } 85 86 public Expression compile(Executable exec) throws XPathException { 87 Expression b = compileSequenceConstructor(exec, iterateAxis(Axis.CHILD), true); 88 if (b != null) { 89 if (select == null) { 90 select = b; 91 } else { 92 select = Block.makeBlock(select, b); 94 } 95 } 96 if (select == null) { 97 select = new StringValue("xsl:message (no content)"); 98 } 99 Message inst = new Message(select, terminate); 100 ExpressionTool.makeParentReferences(inst); 101 return inst; 102 } 103 104 } 105 | Popular Tags |