1 package com.icl.saxon.style; 2 import com.icl.saxon.tree.AttributeCollection; 3 import com.icl.saxon.tree.NodeImpl; 4 import com.icl.saxon.*; 5 import com.icl.saxon.expr.*; 6 import com.icl.saxon.om.NodeInfo; 7 8 import javax.xml.transform.*; 9 10 11 15 16 public class SAXONReturn extends XSLGeneralVariable { 17 18 22 23 public boolean isInstruction() { 24 return true; 25 } 26 27 public int getVariableFingerprint() { 28 return -1; 29 } 30 31 public void prepareAttributes() throws TransformerConfigurationException { 32 33 StandardNames sn = getStandardNames(); 34 AttributeCollection atts = getAttributeList(); 35 36 String selectAtt = null; 37 38 for (int a=0; a<atts.getLength(); a++) { 39 int nc = atts.getNameCode(a); 40 int f = nc & 0xfffff; 41 if (f==sn.SELECT) { 42 selectAtt = atts.getValue(a); 43 } else { 44 checkUnknownAttribute(nc); 45 } 46 } 47 48 if (selectAtt!=null) { 49 select = makeExpression(selectAtt); 50 } 51 52 } 53 54 55 58 59 public void validate() throws TransformerConfigurationException { 60 61 63 NodeInfo anc = (NodeInfo)getParentNode(); 64 while (anc!=null) { 65 if (anc instanceof SAXONFunction) break; 66 if (anc instanceof XSLGeneralVariable ) { 67 compileError(getDisplayName() + " must not be used within a variable definition"); 68 }; 69 anc = (NodeInfo)anc.getParent(); 70 } 71 72 if (anc==null) { 73 compileError(getDisplayName() + " must only be used within a function definition"); 74 } 75 76 77 79 NodeImpl next = (NodeImpl)getNextSibling(); 80 if (next!=null && !(next instanceof XSLFallback)) { 81 compileError(getDisplayName() + " must be the last instruction in its template body"); 82 } 83 84 if (select==null) { 85 if (!hasChildNodes()) { 86 select = new StringValue(""); 87 } 88 } 89 } 90 91 94 95 public void process(Context context) throws TransformerException 96 { 97 Value value = getSelectValue(context); 98 context.setReturnValue(value); 99 } 100 101 } 102 103 | Popular Tags |