| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 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 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
public class XSLStylesheet extends XSLModuleRoot { |
| 26 |
|
| 27 |
|
| 28 |
protected boolean mayContainParam() { |
| 29 |
return true; |
| 30 |
} |
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 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 |
|
| 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 |
|
| 75 |
break; |
| 76 |
case "preserve": |
| 77 |
|
| 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 |
|
| 94 |
|
| 95 |
|
| 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 |
|
| 113 |
} else if (!NamespaceConstant.XSLT.equals(curr.getURI()) && !"".equals(curr.getURI())) { |
| 114 |
|
| 115 |
} else if (curr instanceof AbsentExtensionElement && ((StyleElement) curr).forwardsCompatibleModeIsEnabled()) { |
| 116 |
|
| 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 |
|