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.Executable; 5 import net.sf.saxon.instruct.While; 6 import net.sf.saxon.om.AttributeCollection; 7 import net.sf.saxon.om.Axis; 8 import net.sf.saxon.value.EmptySequence; 9 import net.sf.saxon.trans.XPathException; 10 11 import javax.xml.transform.TransformerConfigurationException ; 12 13 14 19 20 public class SaxonWhile extends StyleElement { 21 22 private Expression test; 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 testAtt=null; 45 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.TEST) { 52 testAtt = atts.getValue(a); 53 } else { 54 checkUnknownAttribute(nc); 55 } 56 } 57 58 if (testAtt==null) { 59 reportAbsence("test"); 60 return; 61 } 62 test = makeExpression(testAtt); 63 } 64 65 public void validate() throws XPathException { 66 checkWithinTemplate(); 67 test = typeCheck("test", test); 68 } 69 70 public Expression compile(Executable exec) throws XPathException { 71 Expression action = compileSequenceConstructor(exec, iterateAxis(Axis.CHILD), true); 72 if (action == null) { 73 action = EmptySequence.getInstance(); 74 } 75 While w = new While(test, action); 77 ExpressionTool.makeParentReferences(w); 78 return w; 79 } 84 85 } 86 87 | Popular Tags |