01: package net.sf.saxon.exslt;
02:
03: import net.sf.saxon.expr.XPathContext;
04: import net.sf.saxon.pattern.AnyNodeTest;
05: import net.sf.saxon.type.ItemType;
06: import net.sf.saxon.type.Type;
07: import net.sf.saxon.type.TypeHierarchy;
08: import net.sf.saxon.value.Value;
09:
10: /**
11: * This class implements extension functions in the
12: * http://exslt.org/common namespace. <p>
13: */
14:
15: public abstract class Common {
16:
17: /**
18: * Class is not instantiated
19: */
20: private Common() {
21: }
22:
23: /**
24: * Convert a result tree fragment to a node-set. This is a hangover from XSLT 1.0;
25: * it is implemented as a no-op.
26: */
27:
28: public static Value nodeSet(Value frag) {
29: return frag;
30: }
31:
32: /**
33: * Return the type of the supplied value: "sequence", "string", "number", "boolean",
34: * "external". (EXSLT spec not yet modified to cater for XPath 2.0 data model)
35: */
36:
37: public static String objectType(XPathContext context, Value value) {
38: final TypeHierarchy th = context.getNamePool()
39: .getTypeHierarchy();
40: ItemType type = value.getItemType(th);
41: if (th.isSubType(type, AnyNodeTest.getInstance())) {
42: return "node-set";
43: } else if (th.isSubType(type, Type.STRING_TYPE)) {
44: return "string";
45: } else if (th.isSubType(type, Type.NUMBER_TYPE)) {
46: return "number";
47: } else if (th.isSubType(type, Type.BOOLEAN_TYPE)) {
48: return "boolean";
49: } else {
50: return type.toString(context.getNamePool());
51: }
52: }
53:
54: }
55:
56: //
57: // The contents of this file are subject to the Mozilla Public License Version 1.0 (the "License");
58: // you may not use this file except in compliance with the License. You may obtain a copy of the
59: // License at http://www.mozilla.org/MPL/
60: //
61: // Software distributed under the License is distributed on an "AS IS" basis,
62: // WITHOUT WARRANTY OF ANY KIND, either express or implied.
63: // See the License for the specific language governing rights and limitations under the License.
64: //
65: // The Original Code is: all this file.
66: //
67: // The Initial Developer of the Original Code is Michael H. Kay.
68: //
69: // Portions created by (your name) are Copyright (C) (your legal entity). All Rights Reserved.
70: //
71: // Contributor(s): none.
72: //
|