1 package com.icl.saxon.style; 2 import com.icl.saxon.tree.AttributeCollection; 3 import com.icl.saxon.*; 4 5 import com.icl.saxon.expr.*; 6 import com.icl.saxon.output.*; 7 import javax.xml.transform.*; 8 import com.icl.saxon.om.NodeInfo; 9 10 11 19 20 public final class XSLValueOf extends StyleElement { 21 22 private Expression select; 23 private boolean disable = false; 24 25 29 30 public boolean isInstruction() { 31 return true; 32 } 33 34 public Expression getSelectExpression() { 35 if (select==null) { 36 return new ContextNodeExpression(); 37 } else { 38 return select; 39 } 40 } 41 42 public boolean getDisableOutputEscaping() { 43 return disable; 44 } 45 46 public void prepareAttributes() throws TransformerConfigurationException { 47 48 String selectAtt = null; 49 String disableAtt = null; 50 51 StandardNames sn = getStandardNames(); 52 AttributeCollection atts = getAttributeList(); 53 54 for (int a=0; a<atts.getLength(); a++) { 55 int nc = atts.getNameCode(a); 56 int f = nc & 0xfffff; 57 if (f==sn.DISABLE_OUTPUT_ESCAPING) { 58 disableAtt = atts.getValue(a); 59 } else if (f==sn.SELECT) { 60 selectAtt = atts.getValue(a); 61 } else { 62 checkUnknownAttribute(nc); 63 } 64 } 65 66 if (selectAtt==null) { 67 reportAbsence("select"); 68 return; 69 } 70 if (selectAtt.trim().equals(".")) { 71 select = null; } else { 73 select = makeExpression(selectAtt); 74 } 75 76 if (disableAtt != null) { 77 if (disableAtt.equals("yes")) { 78 disable = true; 79 } else if (disableAtt.equals("no")) { 80 disable = false; 81 } else { 82 compileError("disable-output-escaping attribute must be either yes or no"); 83 } 84 } 85 86 87 } 88 89 public void validate() throws TransformerConfigurationException { 90 checkWithinTemplate(); 91 checkEmpty(); 92 } 93 94 public void process(Context context) throws TransformerException 95 { 96 Outputter out = context.getOutputter(); 97 if (disable) out.setEscaping(false); 98 99 if (select==null) { 100 (context.getCurrentNodeInfo()).copyStringValue(out); 101 } else { 102 select.outputStringValue(out, context); 103 } 104 105 if (disable) out.setEscaping(true); 106 } 107 108 } 109 110 | Popular Tags |