| 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.expr.instruct.ApplyImports; |
| 12 |
import net.sf.saxon.expr.instruct.WithParam; |
| 13 |
import net.sf.saxon.om.AttributeCollection; |
| 14 |
import net.sf.saxon.om.AxisInfo; |
| 15 |
import net.sf.saxon.om.NodeInfo; |
| 16 |
import net.sf.saxon.trans.XPathException; |
| 17 |
import net.sf.saxon.tree.iter.AxisIterator; |
| 18 |
import net.sf.saxon.tree.linked.NodeImpl; |
| 19 |
import net.sf.saxon.type.Type; |
| 20 |
import net.sf.saxon.value.Whitespace; |
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
public class XSLApplyImports extends StyleElement { |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public boolean isInstruction() { |
| 36 |
return true; |
| 37 |
} |
| 38 |
|
| 39 |
public void prepareAttributes() throws XPathException { |
| 40 |
|
| 41 |
AttributeCollection atts = getAttributeList(); |
| 42 |
|
| 43 |
for (int a = 0; a < atts.getLength(); a++) { |
| 44 |
checkUnknownAttribute(atts.getNodeName(a)); |
| 45 |
} |
| 46 |
} |
| 47 |
|
| 48 |
public void validate(ComponentDeclaration decl) throws XPathException { |
| 49 |
|
| 50 |
AxisIterator kids = iterateAxis(AxisInfo.CHILD); |
| 51 |
while (true) { |
| 52 |
NodeInfo child = kids.next(); |
| 53 |
if (child == null) { |
| 54 |
break; |
| 55 |
} |
| 56 |
if (child instanceof XSLWithParam) { |
| 57 |
|
| 58 |
} else if (child.getNodeKind() == Type.TEXT) { |
| 59 |
|
| 60 |
if (!Whitespace.isWhite(child.getStringValueCS())) { |
| 61 |
compileError("No character data is allowed within xsl:apply-imports", "XTSE0010"); |
| 62 |
} |
| 63 |
} else { |
| 64 |
compileError("Child element " + child.getDisplayName() + |
| 65 |
" is not allowed as a child of xsl:apply-imports", "XTSE0010"); |
| 66 |
} |
| 67 |
} |
| 68 |
|
| 69 |
NodeImpl parent = getParent(); |
| 70 |
while (parent != null) { |
| 71 |
if (parent instanceof XSLOverride) { |
| 72 |
compileError("xsl:apply-imports cannot be used in a template rule declared within xsl:override", "XTSE3460"); |
| 73 |
} |
| 74 |
parent = parent.getParent(); |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
public Expression compile(Compilation exec, ComponentDeclaration decl) throws XPathException { |
| 80 |
ApplyImports inst = new ApplyImports(); |
| 81 |
WithParam[] nonTunnels = getWithParamInstructions(inst, exec, decl, false); |
| 82 |
WithParam[] tunnels = getWithParamInstructions(inst, exec, decl, true); |
| 83 |
inst.setActualParams(nonTunnels); |
| 84 |
inst.setTunnelParams(tunnels); |
| 85 |
return inst; |
| 86 |
} |
| 87 |
|
| 88 |
} |
| 89 |
|