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.om.NodeInfo; 6 import com.icl.saxon.expr.*; 7 import com.icl.saxon.output.*; 8 import javax.xml.transform.*; 9 10 import org.w3c.dom.Node ; 11 12 15 16 public class XSLText extends StyleElement { 17 18 private boolean disable = false; 19 private String value = null; 20 21 22 26 27 public boolean isInstruction() { 28 return true; 29 } 30 31 public void prepareAttributes() throws TransformerConfigurationException { 32 33 String disableAtt = null; 34 35 StandardNames sn = getStandardNames(); 36 AttributeCollection atts = getAttributeList(); 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.DISABLE_OUTPUT_ESCAPING) { 42 disableAtt = atts.getValue(a); 43 } else { 44 checkUnknownAttribute(nc); 45 } 46 } 47 48 if (disableAtt != null) { 49 if (disableAtt.equals("yes")) { 50 disable = true; 51 } else if (disableAtt.equals("no")) { 52 disable = false; 53 } else { 54 compileError("disable-output-escaping attribute must be either yes or no"); 55 } 56 } 57 } 58 59 public void validate() throws TransformerConfigurationException { 60 checkWithinTemplate(); 61 NodeImpl node = (NodeImpl)getFirstChild(); 62 if (node==null) { 63 value = ""; 64 } else { 65 value = node.getStringValue(); 66 while (node!=null) { 67 if (node.getNodeType()==NodeInfo.ELEMENT) { 68 compileError("xsl:text must not have any child elements"); 69 } 70 node = (NodeImpl)node.getNextSibling(); 71 } 72 } 73 } 74 75 public void process(Context context) throws TransformerException { 76 if (!value.equals("")) { 77 Outputter out = context.getOutputter(); 78 if (disable) { 79 out.setEscaping(false); 80 out.writeContent(value); 81 out.setEscaping(true); 82 } else { 83 out.writeContent(value); 84 } 85 } 86 } 87 88 } 89 90 | Popular Tags |