Debian Codegraph @

net/sf/saxon/style/XSLStylesheet.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.lib.NamespaceConstant;
11 import net.sf.saxon.om.AttributeCollection;
12 import net.sf.saxon.om.AxisInfo;
13 import net.sf.saxon.om.NodeInfo;
14 import net.sf.saxon.trans.XPathException;
15 import net.sf.saxon.tree.iter.AxisIterator;
16 import net.sf.saxon.type.Type;
17
18 /**
19 * An xsl:stylesheet or xsl:transform element in the stylesheet. <br>
20 * Note this element represents a stylesheet module, not necessarily
21 * the whole stylesheet. However, much of the functionality (and the fields)
22 * are relevant only to the top-level module.
23 */
24
25 public class XSLStylesheet extends XSLModuleRoot {
26
27
28 protected boolean mayContainParam() {
29 return true;
30 }
31
32
33 /**
34 * Prepare the attributes on the stylesheet element
35 */
36
37 public void prepareAttributes() throws XPathException {
38
39 processDefaultCollationAttribute();
40 processDefaultMode();
41 String inputTypeAnnotationsAtt = null;
42 AttributeCollection atts = getAttributeList();
43 for (int a = 0; a < atts.getLength(); a++) {
44
45 String f = atts.getQName(a);
46 switch (f) {
47 case "version":
48 // already processed
49 break;
50 case "id":
51 //
52 break;
53 case "extension-element-prefixes":
54 //
55 break;
56 case "exclude-result-prefixes":
57 //
58 break;
59 case "input-type-annotations":
60 inputTypeAnnotationsAtt = atts.getValue(a);
61 break;
62 default:
63 checkUnknownAttribute(atts.getNodeName(a));
64 break;
65 }
66 }
67 if (version == -1 && (getParent() == null || getParent().getNodeKind() == Type.DOCUMENT)) {
68 reportAbsence("version");
69 }
70
71 if (inputTypeAnnotationsAtt != null) {
72 switch (inputTypeAnnotationsAtt) {
73 case "strip":
74 //setInputTypeAnnotations(ANNOTATION_STRIP);
75 break;
76 case "preserve":
77 //setInputTypeAnnotations(ANNOTATION_PRESERVE);
78 break;
79 case "unspecified":
80 //
81 break;
82 default:
83 invalidAttribute("input-type-annotations", "strip|preserve|unspecified");
84 break;
85 }
86 }
87
88 }
89
90
91
92 /**
93 * Validate this element
94 *
95 * @param decl Not used
96 */
97
98 public void validate(ComponentDeclaration decl) throws XPathException {
99 if (validationError != null) {
100 compileError(validationError);
101 }
102 if (getParent() != null && getParent().getNodeKind() != Type.DOCUMENT) {
103 compileError(getDisplayName() + " must be the outermost element", "XTSE0010");
104 }
105
106 AxisIterator kids = iterateAxis(AxisInfo.CHILD);
107 NodeInfo curr;
108 while ((curr = kids.next()) != null) {
109 if (curr.getNodeKind() == Type.TEXT ||
110 (curr instanceof StyleElement && ((StyleElement) curr).isDeclaration()) ||
111 curr instanceof DataElement) {
112 // all is well
113 } else if (!NamespaceConstant.XSLT.equals(curr.getURI()) && !"".equals(curr.getURI())) {
114 // elements in other namespaces are allowed and ignored
115 } else if (curr instanceof AbsentExtensionElement && ((StyleElement) curr).forwardsCompatibleModeIsEnabled()) {
116 // this is OK: an unknown XSLT element is allowed in forwards compatibility mode
117 } else if (NamespaceConstant.XSLT.equals(curr.getURI())) {
118 assert curr instanceof StyleElement;
119 ((StyleElement) curr).compileError("Element " + curr.getDisplayName() +
120 " must not appear directly within " + getDisplayName(), "XTSE0010");
121 } else {
122 assert curr instanceof StyleElement;
123 ((StyleElement) curr).compileError("Element " + curr.getDisplayName() +
124 " must not appear directly within " + getDisplayName() +
125 " because it is not in a namespace", "XTSE0130");
126 }
127 }
128 }
129
130
131
132
133
134 }
135