1 16 19 20 package org.apache.xalan.xsltc.dom; 21 22 import org.apache.xalan.xsltc.DOM; 23 import org.apache.xalan.xsltc.Translet; 24 import org.apache.xml.dtm.DTMAxisIterator; 25 26 30 public abstract class AnyNodeCounter extends NodeCounter { 31 public AnyNodeCounter(Translet translet, 32 DOM document, DTMAxisIterator iterator) { 33 super(translet, document, iterator); 34 } 35 36 public NodeCounter setStartNode(int node) { 37 _node = node; 38 _nodeType = _document.getExpandedTypeID(node); 39 return this; 40 } 41 42 public String getCounter() { 43 int result; 44 if (_value != Integer.MIN_VALUE) { 45 result = _value; 46 } 47 else { 48 int next = _node; 49 final int root = _document.getDocument(); 50 result = 0; 51 while (next >= root && !matchesFrom(next)) { 52 if (matchesCount(next)) { 53 ++result; 54 } 55 next--; 56 66 } 67 } 68 return formatNumbers(result); 69 } 70 71 public static NodeCounter getDefaultNodeCounter(Translet translet, 72 DOM document, 73 DTMAxisIterator iterator) { 74 return new DefaultAnyNodeCounter(translet, document, iterator); 75 } 76 77 static class DefaultAnyNodeCounter extends AnyNodeCounter { 78 public DefaultAnyNodeCounter(Translet translet, 79 DOM document, DTMAxisIterator iterator) { 80 super(translet, document, iterator); 81 } 82 83 public String getCounter() { 84 int result; 85 if (_value != Integer.MIN_VALUE) { 86 result = _value; 87 } 88 else { 89 int next = _node; 90 result = 0; 91 final int ntype = _document.getExpandedTypeID(_node); 92 final int root = _document.getDocument(); 93 while (next >= 0) { 94 if (ntype == _document.getExpandedTypeID(next)) { 95 result++; 96 } 97 if (next == root) { 100 break; 101 } 102 else { 103 --next; 104 } 105 } 106 } 107 return formatNumbers(result); 108 } 109 } 110 } 111 | Popular Tags |