1 package com.icl.saxon.style; 2 import com.icl.saxon.tree.AttributeCollection; 3 import com.icl.saxon.*; 4 import com.icl.saxon.om.*; 5 import com.icl.saxon.tree.NodeImpl; 6 import com.icl.saxon.expr.*; 7 import com.icl.saxon.trace.*; 9 import javax.xml.transform.*; 10 11 14 15 public class XSLChoose extends StyleElement { 16 17 private StyleElement otherwise; 18 19 23 24 public boolean isInstruction() { 25 return true; 26 } 27 28 32 33 public boolean doesPostProcessing() { 34 return false; 35 } 36 37 public void prepareAttributes() throws TransformerConfigurationException { 38 AttributeCollection atts = getAttributeList(); 39 for (int a=0; a<atts.getLength(); a++) { 40 int nc = atts.getNameCode(a); 41 checkUnknownAttribute(nc); 42 } 43 } 44 45 public void validate() throws TransformerConfigurationException { 46 checkWithinTemplate(); 47 48 NodeImpl xslwhen = null; 49 50 NodeImpl curr = (NodeImpl)getFirstChild(); 51 while(curr!=null) { 52 if (curr instanceof XSLWhen) { 53 if (otherwise!=null) { 54 compileError("xsl:otherwise must come last"); 55 } 56 xslwhen = curr; 57 } else if (curr instanceof XSLOtherwise) { 58 if (otherwise!=null) { 59 compileError("Only one xsl:otherwise allowed in an xsl:choose"); 60 } else { 61 otherwise = (StyleElement)curr; 62 } 63 } else { 64 compileError("Only xsl:when and xsl:otherwise are allowed here"); 65 } 66 curr = (NodeImpl)curr.getNextSibling(); 67 } 68 69 if (xslwhen==null) 70 compileError("xsl:choose must contain at least one xsl:when"); 71 } 72 73 public void process(Context context) throws TransformerException 74 { 75 boolean isTracing = context.getController().isTracing(); StyleElement option = (StyleElement)getFirstChild(); 77 78 80 while (option!=null) { 81 boolean go; 82 83 if (option instanceof XSLWhen) { 84 go = ((XSLWhen)option).getCondition().evaluateAsBoolean(context); 85 } else { go = true; 87 } 88 89 if (go) { 90 if (isTracing) { TraceListener listener = context.getController().getTraceListener(); 92 listener.enter(option, context); 93 option.process(context); 94 listener.leave(option, context); 95 } else { 96 option.process(context); 97 } 98 option = null; 99 } else { 100 option = (StyleElement)option.getNextSibling(); 101 } 102 } 103 104 } 105 106 107 } 108 109 | Popular Tags |