1 package net.sf.saxon.style; 2 import net.sf.saxon.Configuration; 3 import net.sf.saxon.expr.Expression; 4 import net.sf.saxon.expr.ExpressionTool; 5 import net.sf.saxon.instruct.CopyOf; 6 import net.sf.saxon.instruct.Executable; 7 import net.sf.saxon.om.AttributeCollection; 8 import net.sf.saxon.om.Validation; 9 import net.sf.saxon.trans.XPathException; 10 import net.sf.saxon.type.SchemaType; 11 12 13 16 17 public final class XSLCopyOf extends StyleElement { 18 19 private Expression select; 20 private boolean copyNamespaces; 21 private int validation = Validation.PRESERVE; 22 private SchemaType schemaType; 23 private boolean readOnce = false; 25 29 30 public boolean isInstruction() { 31 return true; 32 } 33 34 public void prepareAttributes() throws XPathException { 35 36 AttributeCollection atts = getAttributeList(); 37 String selectAtt = null; 38 String copyNamespacesAtt = null; 39 String validationAtt = null; 40 String typeAtt = null; 41 String readOnceAtt = null; 42 43 for (int a=0; a<atts.getLength(); a++) { 44 int nc = atts.getNameCode(a); 45 String f = getNamePool().getClarkName(nc); 46 if (f==StandardNames.SELECT) { 47 selectAtt = atts.getValue(a); 48 } else if (f==StandardNames.COPY_NAMESPACES) { 49 copyNamespacesAtt = atts.getValue(a).trim(); 50 } else if (f==StandardNames.VALIDATION) { 51 validationAtt = atts.getValue(a).trim(); 52 } else if (f==StandardNames.TYPE) { 53 typeAtt = atts.getValue(a).trim(); 54 } else if (f==StandardNames.SAXON_READ_ONCE) { 55 readOnceAtt = atts.getValue(a).trim(); 56 } else { 57 checkUnknownAttribute(nc); 58 } 59 } 60 61 if (selectAtt!=null) { 62 select = makeExpression(selectAtt); 63 } else { 64 reportAbsence("select"); 65 } 66 67 if (copyNamespacesAtt == null) { 68 copyNamespaces = true; 69 } else { 70 if (copyNamespacesAtt.equals("yes")) { 71 copyNamespaces = true; 72 } else if (copyNamespacesAtt.equals("no")) { 73 copyNamespaces = false; 74 } else { 75 compileError("Value of copy-namespaces must be 'yes' or 'no'", "XTSE0020"); 76 } 77 } 78 79 if (validationAtt!=null) { 80 validation = Validation.getCode(validationAtt); 81 if (validation != Validation.STRIP && !getConfiguration().isSchemaAware(Configuration.XSLT)) { 82 compileError("To perform validation, a schema-aware XSLT processor is needed", "XTSE1660"); 83 } 84 if (validation == Validation.INVALID) { 85 compileError("invalid value of validation attribute", "XTSE0020"); 86 } 87 } else { 88 validation = getContainingStylesheet().getDefaultValidation(); 89 } 90 91 if (typeAtt!=null) { 92 schemaType = getSchemaType(typeAtt); 93 if (!getConfiguration().isSchemaAware(Configuration.XSLT)) { 94 compileError("The @type attribute is available only with a schema-aware XSLT processor", "XTSE1660"); 95 } 96 } 97 98 if (typeAtt != null && validationAtt != null) { 99 compileError("The @validation and @type attributes are mutually exclusive", "XTSE1505"); 100 } 101 102 if (validation == Validation.PRESERVE && !copyNamespaces) { 103 compileError("copy-namespaces must be set to 'yes' when validation is set to 'preserve'", "XTSE0950"); 104 } 105 106 if (readOnceAtt != null) { 107 if (readOnceAtt.equals("yes")) { 108 readOnce = true; 109 } else if (readOnceAtt.equals("no")) { 110 readOnce = false; 111 } else { 112 compileError("saxon:read-once attribute must be 'yes' or 'no'"); 113 } 114 } 115 } 116 117 public void validate() throws XPathException { 118 checkWithinTemplate(); 119 checkEmpty(); 120 select = typeCheck("select", select); 121 } 122 123 public Expression compile(Executable exec) { 124 CopyOf inst = new CopyOf(select, copyNamespaces, validation, schemaType, false); 125 if (readOnce) { 126 inst.setReadOnce(readOnce); 127 } 128 ExpressionTool.makeParentReferences(inst); 129 return inst; 130 } 131 132 } 133 134 | Popular Tags |