1 package net.sf.saxon.functions; 2 import net.sf.saxon.expr.Expression; 3 import net.sf.saxon.expr.StaticContext; 4 import net.sf.saxon.expr.StaticProperty; 5 import net.sf.saxon.expr.XPathContext; 6 import net.sf.saxon.om.EmptyIterator; 7 import net.sf.saxon.om.Item; 8 import net.sf.saxon.om.SequenceIterator; 9 import net.sf.saxon.sort.GroupIterator; 10 import net.sf.saxon.trans.XPathException; 11 12 15 16 public class CurrentGroup extends SystemFunction implements XSLTFunction { 17 18 public static final int CURRENT_GROUP = 0; 19 public static final int CURRENT_GROUPING_KEY = 1; 20 21 25 26 public Expression preEvaluate(StaticContext env) { 27 return this; 28 } 29 30 33 34 public Item evaluateItem(XPathContext c) throws XPathException { 35 if (operation==CURRENT_GROUPING_KEY) { 36 GroupIterator gi = c.getCurrentGroupIterator(); 37 if (gi==null) { 38 return null; 39 } 40 return gi.getCurrentGroupingKey(); 41 } else { 42 return super.evaluateItem(c); 43 } 44 } 45 46 49 50 public SequenceIterator iterate(XPathContext c) throws XPathException { 51 if (operation==CURRENT_GROUP) { 52 GroupIterator gi = c.getCurrentGroupIterator(); 53 if (gi==null) { 54 return EmptyIterator.getInstance(); 55 } 56 return gi.iterateCurrentGroup(); 57 } else { 58 return super.iterate(c); 59 } 60 } 61 62 65 66 public int getIntrinsicDependencies() { 67 return StaticProperty.DEPENDS_ON_CURRENT_GROUP; 68 } 69 70 } 71 72 73 74 75 | Popular Tags |