1 package com.icl.saxon.style; 2 import com.icl.saxon.tree.AttributeCollection; 3 import com.icl.saxon.tree.NodeImpl; 4 import com.icl.saxon.*; 5 import com.icl.saxon.om.*; 6 7 import com.icl.saxon.expr.*; 8 import javax.xml.transform.*; 9 import java.util.*; 10 11 15 16 public class SAXONGroup extends XSLForEach { 17 18 Expression groupBy = null; 19 20 24 25 public boolean isInstruction() { 26 return true; 27 } 28 29 30 public void prepareAttributes() throws TransformerConfigurationException { 31 32 StandardNames sn = getStandardNames(); 33 AttributeCollection atts = getAttributeList(); 34 35 String selectAtt = null; 36 String groupByAtt = null; 37 38 for (int a=0; a<atts.getLength(); a++) { 39 int nc = atts.getNameCode(a); 40 int f = nc & 0xfffff; 41 if (f==sn.SELECT) { 42 selectAtt = atts.getValue(a); 43 } else if (f==sn.GROUP_BY) { 44 groupByAtt = atts.getValue(a); 45 } else { 46 checkUnknownAttribute(nc); 47 } 48 } 49 50 if (selectAtt==null) { 51 reportAbsence("select"); 52 } else { 53 select = makeExpression(selectAtt); 54 } 55 56 if (groupByAtt == null) { 57 reportAbsence("group-by"); 58 } else { 59 groupBy = makeExpression(groupByAtt); 60 } 61 } 62 63 public void validate() throws TransformerConfigurationException { 64 checkWithinTemplate(); 65 select = handleSortKeys(select); 67 NodeImpl n = this; 69 SAXONItem item = null; 70 while(n!=null) { 71 if (n instanceof SAXONItem) { 72 item = (SAXONItem)n; 73 break; 74 } 75 n = n.getNextInDocument(this); 76 } 77 if (item==null) { 78 compileError("saxon:group must have a nested saxon:item element"); 79 } 80 } 81 82 public void process(Context context) throws TransformerException 83 { 84 NodeEnumeration selection = select.enumerate(context, false); 85 if (!(selection instanceof LastPositionFinder)) { 86 selection = new LookaheadEnumerator(selection); 87 } 88 89 Context c = context.newContext(); 90 c.setLastPositionFinder((LastPositionFinder)selection); 91 92 94 GroupActivation activation = new GroupActivation(this, groupBy, selection, c); 95 Stack stack = c.getGroupActivationStack(); 96 stack.push(activation); 97 98 while(activation.hasMoreElements()) { 99 activation.nextElement(); 100 processChildren(c); 101 context.setReturnValue(c.getReturnValue()); 102 } 103 104 stack.pop(); 105 } 106 107 } 108 109 | Popular Tags |