| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.style; |
| 9 |
|
| 10 |
import net.sf.saxon.expr.Expression; |
| 11 |
import net.sf.saxon.expr.Literal; |
| 12 |
import net.sf.saxon.expr.instruct.DocumentInstr; |
| 13 |
import net.sf.saxon.lib.Validation; |
| 14 |
import net.sf.saxon.om.AttributeCollection; |
| 15 |
import net.sf.saxon.trans.XPathException; |
| 16 |
import net.sf.saxon.type.SchemaType; |
| 17 |
import net.sf.saxon.value.Whitespace; |
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
public class XSLDocument extends StyleElement { |
| 26 |
|
| 27 |
private int validationAction = Validation.STRIP; |
| 28 |
private SchemaType schemaType = null; |
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
public boolean isInstruction() { |
| 37 |
return true; |
| 38 |
} |
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
public boolean mayContainSequenceConstructor() { |
| 47 |
return true; |
| 48 |
} |
| 49 |
|
| 50 |
public void prepareAttributes() throws XPathException { |
| 51 |
AttributeCollection atts = getAttributeList(); |
| 52 |
|
| 53 |
String validationAtt = null; |
| 54 |
String typeAtt = null; |
| 55 |
|
| 56 |
for (int a = 0; a < atts.getLength(); a++) { |
| 57 |
String f = atts.getQName(a); |
| 58 |
if (f.equals("validation")) { |
| 59 |
validationAtt = Whitespace.trim(atts.getValue(a)); |
| 60 |
} else if (f.equals("type")) { |
| 61 |
typeAtt = Whitespace.trim(atts.getValue(a)); |
| 62 |
} else { |
| 63 |
checkUnknownAttribute(atts.getNodeName(a)); |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
if (validationAtt == null) { |
| 68 |
validationAction = getDefaultValidation(); |
| 69 |
} else { |
| 70 |
validationAction = validateValidationAttribute(validationAtt); |
| 71 |
} |
| 72 |
if (typeAtt != null) { |
| 73 |
if (!isSchemaAware()) { |
| 74 |
compileError("The @type attribute is available only with a schema-aware XSLT processor", "XTSE1660"); |
| 75 |
} |
| 76 |
schemaType = getSchemaType(typeAtt); |
| 77 |
validationAction = Validation.BY_TYPE; |
| 78 |
} |
| 79 |
|
| 80 |
if (typeAtt != null && validationAtt != null) { |
| 81 |
compileError("The @validation and @type attributes are mutually exclusive", "XTSE1505"); |
| 82 |
} |
| 83 |
} |
| 84 |
|
| 85 |
public void validate(ComponentDeclaration decl) throws XPathException { |
| 86 |
|
| 87 |
} |
| 88 |
|
| 89 |
public Expression compile(Compilation exec, ComponentDeclaration decl) throws XPathException { |
| 90 |
|
| 91 |
DocumentInstr inst = new DocumentInstr(false, null); |
| 92 |
inst.setValidationAction(validationAction, schemaType); |
| 93 |
Expression b = compileSequenceConstructor(exec, decl, true); |
| 94 |
if (b == null) { |
| 95 |
b = Literal.makeEmptySequence(); |
| 96 |
} |
| 97 |
inst.setContentExpression(b); |
| 98 |
inst.setLocation(allocateLocation()); |
| 99 |
return inst; |
| 100 |
} |
| 101 |
|
| 102 |
} |
| 103 |
|