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