| 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.Block; |
| 12 |
import net.sf.saxon.expr.instruct.Fork; |
| 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 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
public class XSLFork extends StyleElement { |
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
public boolean isInstruction() { |
| 32 |
return true; |
| 33 |
} |
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
public boolean mayContainSequenceConstructor() { |
| 42 |
return false; |
| 43 |
} |
| 44 |
|
| 45 |
|
| 46 |
public void prepareAttributes() throws XPathException { |
| 47 |
|
| 48 |
AttributeCollection atts = getAttributeList(); |
| 49 |
|
| 50 |
for (int a = 0; a < atts.getLength(); a++) { |
| 51 |
checkUnknownAttribute(atts.getNodeName(a)); |
| 52 |
} |
| 53 |
} |
| 54 |
|
| 55 |
|
| 56 |
public void validate(ComponentDeclaration decl) throws XPathException { |
| 57 |
AxisIterator kids = iterateAxis(AxisInfo.CHILD); |
| 58 |
NodeInfo child; |
| 59 |
int foundGroup = 0; |
| 60 |
int foundSequence = 0; |
| 61 |
while ((child = kids.next()) != null) { |
| 62 |
if (child instanceof XSLSequence) { |
| 63 |
foundSequence++; |
| 64 |
} else if (child instanceof XSLForEachGroup) { |
| 65 |
foundGroup++; |
| 66 |
} else if (child instanceof XSLFallback) { |
| 67 |
|
| 68 |
} else { |
| 69 |
compileError(child.getDisplayName() + " cannot appear as a child of xsl:fork"); |
| 70 |
} |
| 71 |
} |
| 72 |
if (foundGroup > 1) { |
| 73 |
compileError("xsl:fork contains more than one xsl:for-each-group instruction"); |
| 74 |
} |
| 75 |
if (foundGroup > 0 && foundSequence > 0) { |
| 76 |
compileError("Cannot mix xsl:sequence and xsl:for-each-group within xsl:fork"); |
| 77 |
} |
| 78 |
} |
| 79 |
|
| 80 |
public Expression compile(Compilation exec, ComponentDeclaration decl) throws XPathException { |
| 81 |
Expression content = compileSequenceConstructor(exec, decl, true); |
| 82 |
if (content instanceof Block) { |
| 83 |
return new Fork(((Block) content).getOperanda()); |
| 84 |
} else { |
| 85 |
return content; |
| 86 |
} |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
} |