Debian Codegraph @

net/sf/saxon/style/XSLDocument.java

raw symbols SCIP
1 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
2 // Copyright (c) 2018 Saxonica Limited.
3 // This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
4 // If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
5 // This Source Code Form is "Incompatible With Secondary Licenses", as defined by the Mozilla Public License, v. 2.0.
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 * An xsl:document instruction in the stylesheet. <BR>
21 * This instruction creates a document node in the result tree, optionally
22 * validating it.
23 */
24
25 public class XSLDocument extends StyleElement {
26
27 private int validationAction = Validation.STRIP;
28 /*@Nullable*/ private SchemaType schemaType = null;
29
30 /**
31 * Determine whether this node is an instruction.
32 *
33 * @return true - it is an instruction
34 */
35
36 public boolean isInstruction() {
37 return true;
38 }
39
40 /**
41 * Determine whether this type of element is allowed to contain a template-body
42 *
43 * @return true: yes, it may contain a template-body
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