Debian Codegraph @

net/sf/saxon/style/XSLCopyOf.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.instruct.CopyOf;
12 import net.sf.saxon.lib.NamespaceConstant;
13 import net.sf.saxon.lib.Validation;
14 import net.sf.saxon.om.AttributeCollection;
15 import net.sf.saxon.trans.SaxonErrorCode;
16 import net.sf.saxon.trans.XPathException;
17 import net.sf.saxon.type.SchemaType;
18 import net.sf.saxon.value.Whitespace;
19
20
21 /**
22 * An xsl:copy-of element in the stylesheet. <br>
23 */
24
25 public final class XSLCopyOf extends StyleElement {
26
27 /*@Nullable*/ private Expression select;
28 private boolean copyNamespaces;
29 private boolean copyAccumulators;
30 private int validation = Validation.PRESERVE;
31 private SchemaType schemaType;
32
33 /**
34 * Determine whether this node is an instruction.
35 *
36 * @return true - it is an instruction
37 */
38
39 public boolean isInstruction() {
40 return true;
41 }
42
43 public void prepareAttributes() throws XPathException {
44
45 AttributeCollection atts = getAttributeList();
46 String selectAtt = null;
47 String copyNamespacesAtt = null;
48 String copyAccumulatorsAtt = null;
49 String validationAtt = null;
50 String typeAtt = null;
51
52 for (int a = 0; a < atts.getLength(); a++) {
53 String f = atts.getQName(a);
54 if (f.equals("select")) {
55 selectAtt = atts.getValue(a);
56 select = makeExpression(selectAtt, a);
57 } else if (f.equals("copy-namespaces")) {
58 copyNamespacesAtt = Whitespace.trim(atts.getValue(a));
59 } else if (f.equals("copy-accumulators")) {
60 copyAccumulatorsAtt = Whitespace.trim(atts.getValue(a));
61 } else if (f.equals("validation")) {
62 validationAtt = Whitespace.trim(atts.getValue(a));
63 } else if (f.equals("type")) {
64 typeAtt = Whitespace.trim(atts.getValue(a));
65 } else if (atts.getLocalName(a).equals("read-once") && atts.getURI(a).equals(NamespaceConstant.SAXON)) {
66 compileError("The saxon:read-once attribute is no longer available - use xsl:stream");
67 } else {
68 checkUnknownAttribute(atts.getNodeName(a));
69 }
70 }
71
72 if (selectAtt == null) {
73 reportAbsence("select");
74 }
75
76 if (copyAccumulatorsAtt == null) {
77 copyAccumulators = false;
78 } else {
79 copyAccumulators = processBooleanAttribute("copy-accumulators", copyAccumulatorsAtt);
80 if (copyAccumulators && isConstructingComplexContent()) {
81 compileWarning("Copying accumulators is pointless when the copied element "
82 + "is immediately attached to a new parent, since that action "
83 + "will lose the accumulator values", SaxonErrorCode.SXWN9017);
84 copyAccumulators = false;
85 }
86 }
87
88 if (copyNamespacesAtt == null) {
89 copyNamespaces = true;
90 } else {
91 copyNamespaces = processBooleanAttribute("copy-namespaces", copyNamespacesAtt);
92 }
93
94 if (validationAtt != null) {
95 validation = validateValidationAttribute(validationAtt);
96 } else {
97 validation = getDefaultValidation();
98 }
99
100 if (typeAtt != null) {
101 schemaType = getSchemaType(typeAtt);
102 if (!isSchemaAware()) {
103 compileError("The @type attribute is available only with a schema-aware XSLT processor", "XTSE1660");
104 }
105 validation = Validation.BY_TYPE;
106 }
107
108 if (typeAtt != null && validationAtt != null) {
109 compileError("The @validation and @type attributes are mutually exclusive", "XTSE1505");
110 }
111
112 }
113
114 public void validate(ComponentDeclaration decl) throws XPathException {
115 checkEmpty();
116 select = typeCheck("select", select);
117 }
118
119 public Expression compile(Compilation exec, ComponentDeclaration decl) {
120 CopyOf inst = new CopyOf(select, copyNamespaces, validation, schemaType, false);
121 inst.setCopyAccumulators(copyAccumulators);
122 //inst.setCopyLineNumbers(exec.getConfiguration().isLineNumbering());
123 inst.setSchemaAware(exec.isSchemaAware());
124 return inst;
125 }
126
127 }
128