1 package net.sf.saxon.functions; 2 import net.sf.saxon.expr.XPathContext; 3 import net.sf.saxon.om.Item; 4 import net.sf.saxon.sort.AtomicComparer; 5 import net.sf.saxon.trans.XPathException; 6 import net.sf.saxon.value.AtomicValue; 7 import net.sf.saxon.value.IntegerValue; 8 9 11 14 15 17 public class Compare extends CollatingFunction { 18 19 22 23 public Item evaluateItem(XPathContext context) throws XPathException { 24 25 AtomicValue arg0 = (AtomicValue)argument[0].evaluateItem(context); 26 if (arg0==null) { 27 return null; 28 } 29 arg0 = arg0.getPrimitiveValue(); 30 31 AtomicValue arg1 = (AtomicValue)argument[1].evaluateItem(context); 32 if (arg1==null) { 33 return null; 34 } 35 arg1 = arg1.getPrimitiveValue(); 36 37 AtomicComparer collator = getAtomicComparer(2, context); 38 39 int result = collator.compare(arg0, arg1); 40 if (result < 0) { 41 return IntegerValue.MINUS_ONE; 42 } else if (result > 0) { 43 return IntegerValue.PLUS_ONE; 44 } else { 45 return IntegerValue.ZERO; 46 } 47 } 48 49 } 50 51 52 | Popular Tags |