| 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.om.AttributeCollection; |
| 12 |
import net.sf.saxon.om.AxisInfo; |
| 13 |
import net.sf.saxon.pattern.NodeKindTest; |
| 14 |
import net.sf.saxon.trans.XPathException; |
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
public class XSLOnCompletion extends StyleElement { |
| 21 |
|
| 22 |
private Expression select; |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
public boolean isInstruction() { |
| 31 |
return true; |
| 32 |
} |
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
public boolean mayContainSequenceConstructor() { |
| 41 |
return true; |
| 42 |
} |
| 43 |
|
| 44 |
public void prepareAttributes() throws XPathException { |
| 45 |
String selectAtt = null; |
| 46 |
|
| 47 |
AttributeCollection atts = getAttributeList(); |
| 48 |
|
| 49 |
for (int a = 0; a < atts.getLength(); a++) { |
| 50 |
String f = atts.getQName(a); |
| 51 |
if (f.equals("select")) { |
| 52 |
selectAtt = atts.getValue(a); |
| 53 |
select = makeExpression(selectAtt, a); |
| 54 |
} else { |
| 55 |
checkUnknownAttribute(atts.getNodeName(a)); |
| 56 |
} |
| 57 |
} |
| 58 |
|
| 59 |
} |
| 60 |
|
| 61 |
public void validate(ComponentDeclaration decl) throws XPathException { |
| 62 |
StyleElement parent = (StyleElement) getParent(); |
| 63 |
if (!(parent instanceof XSLIterate)) { |
| 64 |
compileError("xsl:on-completion is not allowed as a child of " + parent.getDisplayName(), "XTSE0010"); |
| 65 |
} |
| 66 |
|
| 67 |
|
| 68 |
iterateAxis(AxisInfo.PRECEDING_SIBLING, NodeKindTest.ELEMENT).forEach(sib -> { |
| 69 |
if (!(sib instanceof XSLFallback || sib instanceof XSLLocalParam)) { |
| 70 |
compileWarning("The rules for xsl:iterate have changed (see W3C bug 24179): " + |
| 71 |
"xsl:on-completion must now be the first child of xsl:iterate after the xsl:param elements", "XTSE0010"); |
| 72 |
} |
| 73 |
}); |
| 74 |
|
| 75 |
if (select != null && iterateAxis(AxisInfo.CHILD).next() != null) { |
| 76 |
compileError("An xsl:on-completion element with a select attribute must be empty", "XTSE3125"); |
| 77 |
} |
| 78 |
select = typeCheck("select", select); |
| 79 |
} |
| 80 |
|
| 81 |
public Expression compile(Compilation exec, ComponentDeclaration decl) throws XPathException { |
| 82 |
if (select == null) { |
| 83 |
return compileSequenceConstructor(exec, decl, true); |
| 84 |
} else { |
| 85 |
return select; |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
} |