| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.trans.rules; |
| 9 |
|
| 10 |
import net.sf.saxon.expr.XPathContext; |
| 11 |
import net.sf.saxon.expr.XPathContextMajor; |
| 12 |
import net.sf.saxon.expr.instruct.ParameterSet; |
| 13 |
import net.sf.saxon.expr.instruct.TailCall; |
| 14 |
import net.sf.saxon.expr.parser.Location; |
| 15 |
import net.sf.saxon.ma.arrays.ArrayFunctionSet; |
| 16 |
import net.sf.saxon.ma.arrays.ArrayItem; |
| 17 |
import net.sf.saxon.om.*; |
| 18 |
import net.sf.saxon.trans.XPathException; |
| 19 |
import net.sf.saxon.type.Type; |
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
public class ShallowSkipRuleSet implements BuiltInRuleSet { |
| 26 |
|
| 27 |
private static ShallowSkipRuleSet THE_INSTANCE = new ShallowSkipRuleSet(); |
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public static ShallowSkipRuleSet getInstance() { |
| 36 |
return THE_INSTANCE; |
| 37 |
} |
| 38 |
|
| 39 |
private ShallowSkipRuleSet() { |
| 40 |
} |
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
|
| 45 |
|
| 46 |
|
| 47 |
|
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
public void process(Item item, ParameterSet parameters, |
| 55 |
ParameterSet tunnelParams, XPathContext context, |
| 56 |
Location locationId) throws XPathException { |
| 57 |
if (item instanceof NodeInfo) { |
| 58 |
NodeInfo node = (NodeInfo) item; |
| 59 |
switch (node.getNodeKind()) { |
| 60 |
case Type.ELEMENT: { |
| 61 |
XPathContextMajor c2 = context.newContext(); |
| 62 |
c2.setOrigin(this); |
| 63 |
c2.trackFocus(node.iterateAxis(AxisInfo.ATTRIBUTE)); |
| 64 |
c2.setCurrentComponent(c2.getCurrentMode()); |
| 65 |
TailCall tc = c2.getCurrentMode().getActor().applyTemplates(parameters, tunnelParams, c2, locationId); |
| 66 |
while (tc != null) { |
| 67 |
tc = tc.processLeavingTail(); |
| 68 |
} |
| 69 |
} |
| 70 |
case Type.DOCUMENT: { |
| 71 |
XPathContextMajor c2 = context.newContext(); |
| 72 |
c2.setOrigin(this); |
| 73 |
c2.trackFocus(node.iterateAxis(AxisInfo.CHILD)); |
| 74 |
c2.setCurrentComponent(c2.getCurrentMode()); |
| 75 |
TailCall tc = c2.getCurrentMode().getActor().applyTemplates(parameters, tunnelParams, c2, locationId); |
| 76 |
while (tc != null) { |
| 77 |
tc = tc.processLeavingTail(); |
| 78 |
} |
| 79 |
return; |
| 80 |
} |
| 81 |
case Type.TEXT: |
| 82 |
case Type.ATTRIBUTE: |
| 83 |
case Type.COMMENT: |
| 84 |
case Type.PROCESSING_INSTRUCTION: |
| 85 |
case Type.NAMESPACE: |
| 86 |
|
| 87 |
} |
| 88 |
} else if (item instanceof ArrayItem) { |
| 89 |
Sequence<?> seq = ArrayFunctionSet.ArrayToSequence.toSequence((ArrayItem) item); |
| 90 |
SequenceIterator<?> members = seq.iterate(); |
| 91 |
XPathContextMajor c2 = context.newContext(); |
| 92 |
c2.setOrigin(this); |
| 93 |
c2.trackFocus(members); |
| 94 |
c2.setCurrentComponent(c2.getCurrentMode()); |
| 95 |
TailCall tc = c2.getCurrentMode().getActor().applyTemplates(parameters, tunnelParams, c2, locationId); |
| 96 |
while (tc != null) { |
| 97 |
tc = tc.processLeavingTail(); |
| 98 |
} |
| 99 |
} else { |
| 100 |
|
| 101 |
} |
| 102 |
} |
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
|
| 109 |
|
| 110 |
|
| 111 |
@Override |
| 112 |
public String getName() { |
| 113 |
return "shallow-skip"; |
| 114 |
} |
| 115 |
|
| 116 |
|
| 117 |
|
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
public int[] getActionForParentNodes(int nodeKind) { |
| 123 |
return new int[]{APPLY_TEMPLATES_TO_ATTRIBUTES, APPLY_TEMPLATES_TO_CHILDREN}; |
| 124 |
} |
| 125 |
} |
| 126 |
|