1 package net.sf.saxon.style; 2 import net.sf.saxon.expr.*; 3 import net.sf.saxon.instruct.Executable; 4 import net.sf.saxon.instruct.ValueOf; 5 import net.sf.saxon.om.AttributeCollection; 6 import net.sf.saxon.pattern.NodeKindTest; 7 import net.sf.saxon.trans.XPathException; 8 import net.sf.saxon.type.ItemType; 9 import net.sf.saxon.type.Type; 10 import net.sf.saxon.value.Cardinality; 11 import net.sf.saxon.value.StringValue; 12 13 14 23 24 public final class XSLValueOf extends XSLStringConstructor { 25 26 private boolean disable = false; 27 private Expression separator; 28 29 34 35 protected ItemType getReturnedItemType() { 36 return NodeKindTest.TEXT; 37 } 38 39 public void prepareAttributes() throws XPathException { 40 41 String selectAtt = null; 42 String disableAtt = null; 43 String separatorAtt = null; 44 45 AttributeCollection atts = getAttributeList(); 46 47 for (int a=0; a<atts.getLength(); a++) { 48 int nc = atts.getNameCode(a); 49 String f = getNamePool().getClarkName(nc); 50 if (f==StandardNames.DISABLE_OUTPUT_ESCAPING) { 51 disableAtt = atts.getValue(a).trim(); 52 } else if (f==StandardNames.SELECT) { 53 selectAtt = atts.getValue(a); 54 } else if (f==StandardNames.SEPARATOR) { 55 separatorAtt = atts.getValue(a); 56 } else { 57 checkUnknownAttribute(nc); 58 } 59 } 60 61 if (selectAtt!=null) { 62 select = makeExpression(selectAtt); 63 } 64 65 if (separatorAtt != null) { 66 separator = makeAttributeValueTemplate(separatorAtt); 67 } 68 69 if (disableAtt != null) { 70 if (disableAtt.equals("yes")) { 71 disable = true; 72 } else if (disableAtt.equals("no")) { 73 disable = false; 74 } else { 75 compileError("disable-output-escaping attribute must be either 'yes' or 'no'", "XTSE0020"); 76 } 77 } 78 } 79 80 public void validate() throws XPathException { 81 super.validate(); 82 checkWithinTemplate(); 83 select = typeCheck("select", select); 84 separator = typeCheck("separator", separator); 85 } 86 87 public Expression compile(Executable exec) throws XPathException { 88 89 if (separator == null && select != null && backwardsCompatibleModeIsEnabled()) { 90 if (!Type.isSubType(select.getItemType(), Type.ANY_ATOMIC_TYPE)) { 91 select = new Atomizer(select, getStaticContext().getConfiguration()); 92 } 93 if (Cardinality.allowsMany(select.getCardinality())) { 94 select = new FirstItemExpression(select); 95 } 96 if (!Type.isSubType(select.getItemType(), Type.STRING_TYPE)) { 97 select = new AtomicSequenceConverter(select, Type.STRING_TYPE); 98 } 99 } else { 100 if (separator == null) { 101 if (select == null) { 102 separator = StringValue.EMPTY_STRING; 103 } else { 104 separator = StringValue.SINGLE_SPACE; 105 } 106 } 107 } 108 ValueOf inst = new ValueOf(select, disable, false); 109 compileContent(exec, inst, separator); 110 ExpressionTool.makeParentReferences(inst); 111 return inst; 112 } 113 114 } 115 116 | Popular Tags |