01: package net.sf.saxon.functions;
02:
03: import net.sf.saxon.expr.XPathContext;
04: import net.sf.saxon.om.Item;
05: import net.sf.saxon.sort.AtomicComparer;
06: import net.sf.saxon.trans.XPathException;
07: import net.sf.saxon.value.AtomicValue;
08: import net.sf.saxon.value.IntegerValue;
09:
10: //import java.util.Comparator;
11:
12: /**
13: * XSLT 2.0 compare() function
14: */
15:
16: // Supports string comparison using a collation
17: public class Compare extends CollatingFunction {
18:
19: /**
20: * Evaluate the expression
21: */
22:
23: public Item evaluateItem(XPathContext context)
24: throws XPathException {
25:
26: AtomicValue arg0 = (AtomicValue) argument[0]
27: .evaluateItem(context);
28: if (arg0 == null) {
29: return null;
30: }
31: arg0 = arg0.getPrimitiveValue();
32:
33: AtomicValue arg1 = (AtomicValue) argument[1]
34: .evaluateItem(context);
35: if (arg1 == null) {
36: return null;
37: }
38: arg1 = arg1.getPrimitiveValue();
39:
40: AtomicComparer collator = getAtomicComparer(2, context);
41:
42: int result = collator.compare(arg0, arg1);
43: if (result < 0) {
44: return IntegerValue.MINUS_ONE;
45: } else if (result > 0) {
46: return IntegerValue.PLUS_ONE;
47: } else {
48: return IntegerValue.ZERO;
49: }
50: }
51:
52: }
53:
54: //
55: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
56: // you may not use this file except in compliance with the License. You may obtain a copy of the
57: // License at http://www.mozilla.org/MPL/
58: //
59: // Software distributed under the License is distributed on an "AS IS" basis,
60: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
61: // See the License for the specific language governing rights and limitations under the License.
62: //
63: // The Original Code is: all this file.
64: //
65: // The Initial Developer of the Original Code is Michael H. Kay.
66: //
67: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
68: //
69: // Contributor(s): none.
70: //
|