1 package net.sf.saxon.exslt; 2 import net.sf.saxon.expr.*; 3 import net.sf.saxon.om.Item; 4 import net.sf.saxon.om.NodeInfo; 5 import net.sf.saxon.om.SequenceIterator; 6 import net.sf.saxon.sort.GlobalOrderComparer; 7 import net.sf.saxon.trans.DynamicError; 8 import net.sf.saxon.trans.XPathException; 9 import net.sf.saxon.value.SingletonNode; 10 11 15 16 public abstract class Sets { 17 18 private Sets() {} 19 20 26 27 public static SequenceIterator intersection(SequenceIterator p1, SequenceIterator p2) throws XPathException { 28 return new IntersectionEnumeration(p1, p2, GlobalOrderComparer.getInstance()); 29 } 30 31 37 38 public static SequenceIterator difference(SequenceIterator p1, SequenceIterator p2) throws XPathException { 39 return new DifferenceEnumeration(p1, p2, GlobalOrderComparer.getInstance()); 40 } 41 42 49 50 public static boolean hasSameNode(SequenceIterator p1, SequenceIterator p2) throws XPathException { 51 SequenceIterator intersection = 52 new IntersectionEnumeration(p1, p2, GlobalOrderComparer.getInstance()); 53 return intersection.next() != null; 54 } 55 56 60 61 public static SequenceIterator leading ( 62 XPathContext context, 63 SequenceIterator ns1, SequenceIterator ns2) throws XPathException { 64 65 NodeInfo first = null; 66 67 69 GlobalOrderComparer comparer = GlobalOrderComparer.getInstance(); 70 while (true) { 71 Item item = ns2.next(); 72 if (item == null) { 73 if (first == null) { 74 return ns1; 75 } 76 break; 77 } 78 if (item instanceof NodeInfo) { 79 NodeInfo node = (NodeInfo)item; 80 if (first==null) { 81 first = node; 82 } else { 83 if (comparer.compare(node, first) < 0) { 84 first = node; 85 } 86 } 87 } else { 88 DynamicError e = new DynamicError( 89 "Operand of leading() contains an item that is not a node"); 90 e.setXPathContext(context); 91 throw e; 92 } 93 } 94 95 97 Expression filter = new IdentityComparison( 98 new ContextItemExpression(), 99 Token.PRECEDES, 100 new SingletonNode(first)); 101 102 return new FilterIterator(ns1, filter, context); 103 104 } 105 106 110 111 public static SequenceIterator trailing ( 112 XPathContext c, 113 SequenceIterator ns1, SequenceIterator ns2) throws XPathException { 114 115 return net.sf.saxon.functions.Extensions.after(c, ns1, ns2); 116 } 117 118 } 119 120 121 122 123 124 | Popular Tags |