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.ValueOf; 6 import net.sf.saxon.om.AttributeCollection; 7 import net.sf.saxon.om.Axis; 8 import net.sf.saxon.om.AxisIterator; 9 import net.sf.saxon.om.Item; 10 import net.sf.saxon.pattern.NodeKindTest; 11 import net.sf.saxon.trans.XPathException; 12 import net.sf.saxon.type.ItemType; 13 import net.sf.saxon.value.StringValue; 14 15 18 19 public class XSLText extends XSLStringConstructor { 20 21 private boolean disable = false; 22 private StringValue value; 23 24 29 30 protected ItemType getReturnedItemType() { 31 return NodeKindTest.TEXT; 32 } 33 34 public void prepareAttributes() throws XPathException { 35 36 String disableAtt = null; 37 38 AttributeCollection atts = getAttributeList(); 39 40 for (int a=0; a<atts.getLength(); a++) { 41 int nc = atts.getNameCode(a); 42 String f = getNamePool().getClarkName(nc); 43 if (f==StandardNames.DISABLE_OUTPUT_ESCAPING) { 44 disableAtt = atts.getValue(a).trim(); 45 } else { 46 checkUnknownAttribute(nc); 47 } 48 } 49 50 if (disableAtt != null) { 51 if (disableAtt.equals("yes")) { 52 disable = true; 53 } else if (disableAtt.equals("no")) { 54 disable = false; 55 } else { 56 compileError("disable-output-escaping attribute must be either 'yes' or 'no'", "XTSE0020"); 57 } 58 } 59 } 60 61 public void validate() throws XPathException { 62 checkWithinTemplate(); 63 64 AxisIterator kids = iterateAxis(Axis.CHILD); 66 value = StringValue.EMPTY_STRING; 67 while(true) { 68 Item child = kids.next(); 69 if (child == null) { 70 break; 71 } else if (child instanceof StyleElement) { 72 ((StyleElement)child).compileError("xsl:text must not contain child elements", "XTSE0010"); 73 return; 74 } else { 75 value = StringValue.makeStringValue(child.getStringValueCS()); 76 continue; 77 } 78 } 79 super.validate(); 80 } 81 82 public Expression compile(Executable exec) throws XPathException { 83 ValueOf inst = new ValueOf(value, disable, false); 84 ExpressionTool.makeParentReferences(inst); 86 return inst; 87 } 88 89 } 90 91 | Popular Tags |