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.DocumentInstr; 6 import net.sf.saxon.instruct.Executable; 7 import net.sf.saxon.om.AttributeCollection; 8 import net.sf.saxon.om.Axis; 9 import net.sf.saxon.om.Validation; 10 import net.sf.saxon.trans.XPathException; 11 import net.sf.saxon.type.SchemaType; 12 import net.sf.saxon.value.EmptySequence; 13 14 19 20 public class XSLDocument extends StyleElement { 21 22 private int validationAction = Validation.STRIP; 23 private SchemaType schemaType = null; 24 25 29 30 public boolean isInstruction() { 31 return true; 32 } 33 34 38 39 public boolean mayContainSequenceConstructor() { 40 return true; 41 } 42 43 public void prepareAttributes() throws XPathException { 44 AttributeCollection atts = getAttributeList(); 45 46 String validationAtt = null; 47 String typeAtt = null; 48 49 for (int a=0; a<atts.getLength(); a++) { 50 int nc = atts.getNameCode(a); 51 String f = getNamePool().getClarkName(nc); 52 if (f==StandardNames.VALIDATION) { 53 validationAtt = atts.getValue(a).trim(); 54 } else if (f==StandardNames.TYPE) { 55 typeAtt = atts.getValue(a).trim(); 56 } else { 57 checkUnknownAttribute(nc); 58 } 59 } 60 61 if (validationAtt==null) { 62 validationAction = getContainingStylesheet().getDefaultValidation(); 63 } else { 64 validationAction = Validation.getCode(validationAtt); 65 if (validationAction != Validation.STRIP && !getConfiguration().isSchemaAware(Configuration.XSLT)) { 66 compileError("To perform validation, a schema-aware XSLT processor is needed", "XTSE1660"); 67 } 68 if (validationAction == Validation.INVALID) { 69 compileError("Invalid value of @validation attribute", "XTSE0020"); 70 } 71 } 72 if (typeAtt!=null) { 73 if (!getConfiguration().isSchemaAware(Configuration.XSLT)) { 74 compileError("The @type attribute is available only with a schema-aware XSLT processor", "XTSE1660"); 75 } 76 schemaType = getSchemaType(typeAtt); 77 } 78 79 if (typeAtt != null && validationAtt != null) { 80 compileError("The @validation and @type attributes are mutually exclusive", "XTSE1505"); 81 } 82 } 83 84 public void validate() throws XPathException { 85 checkWithinTemplate(); 86 } 87 88 public Expression compile(Executable exec) throws XPathException { 89 90 DocumentInstr inst = new DocumentInstr(false, null, getBaseURI()); 91 inst.setValidationAction(validationAction); 92 inst.setSchemaType(schemaType); 93 Expression b = compileSequenceConstructor(exec, iterateAxis(Axis.CHILD), true); 94 if (b == null) { 95 b = EmptySequence.getInstance(); 96 } 97 inst.setContentExpression(b); 98 ExpressionTool.makeParentReferences(inst); 99 return inst; 100 } 101 102 } 103 104 | Popular Tags |