| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
package net.sf.saxon.functions; |
| 9 |
|
| 10 |
import net.sf.saxon.expr.*; |
| 11 |
import net.sf.saxon.expr.instruct.CopyOf; |
| 12 |
import net.sf.saxon.lib.Validation; |
| 13 |
import net.sf.saxon.om.*; |
| 14 |
import net.sf.saxon.trans.XPathException; |
| 15 |
import net.sf.saxon.tree.wrapper.VirtualCopy; |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
public class CopyOfFn extends SystemFunction { |
| 21 |
|
| 22 |
public int getCardinality(Expression[] arguments) { |
| 23 |
return arguments[0].getCardinality(); |
| 24 |
} |
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
public Sequence<?> call(final XPathContext context, Sequence[] arguments) throws XPathException { |
| 36 |
Sequence<?> in = arguments.length == 0 ? context.getContextItem() : arguments[0]; |
| 37 |
SequenceIterator<?> input = in.iterate(); |
| 38 |
SequenceIterator<?> output = new ItemMappingIterator<>(input, item -> { |
| 39 |
if (!(item instanceof NodeInfo)) { |
| 40 |
return item; |
| 41 |
} else { |
| 42 |
VirtualCopy vc = VirtualCopy.makeVirtualCopy((NodeInfo) item); |
| 43 |
vc.getTreeInfo().setCopyAccumulators(true); |
| 44 |
|
| 45 |
return vc; |
| 46 |
} |
| 47 |
}); |
| 48 |
return new LazySequence<>(output); |
| 49 |
} |
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
@Override |
| 62 |
public Expression makeFunctionCall(Expression... arguments) { |
| 63 |
Expression arg; |
| 64 |
if (arguments.length == 0) { |
| 65 |
arg = new ContextItemExpression(); |
| 66 |
} else { |
| 67 |
arg = arguments[0]; |
| 68 |
} |
| 69 |
CopyOf fn = new CopyOf(arg, true, Validation.PRESERVE, null, false); |
| 70 |
fn.setCopyAccumulators(true); |
| 71 |
fn.setSchemaAware(false); |
| 72 |
return fn; |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|