01: /*
02: * This file is part of PFIXCORE.
03: *
04: * PFIXCORE is free software; you can redistribute it and/or modify
05: * it under the terms of the GNU Lesser General Public License as published by
06: * the Free Software Foundation; either version 2 of the License, or
07: * (at your option) any later version.
08: *
09: * PFIXCORE is distributed in the hope that it will be useful,
10: * but WITHOUT ANY WARRANTY; without even the implied warranty of
11: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12: * GNU Lesser General Public License for more details.
13: *
14: * You should have received a copy of the GNU Lesser General Public License
15: * along with PFIXCORE; if not, write to the Free Software
16: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17: *
18: */
19:
20: package de.schlund.pfixxml.util.xsltimpl;
21:
22: import java.util.ArrayList;
23: import java.util.List;
24:
25: import javax.xml.transform.TransformerException;
26:
27: import org.w3c.dom.Node;
28:
29: import com.icl.saxon.Context;
30: import com.icl.saxon.expr.Expression;
31: import com.icl.saxon.expr.NodeSetValue;
32: import com.icl.saxon.expr.StandaloneContext;
33: import com.icl.saxon.om.NodeEnumeration;
34: import com.icl.saxon.om.NodeInfo;
35:
36: import de.schlund.pfixxml.util.XPathSupport;
37:
38: /**
39: * @author mleidig@schlund.de
40: */
41: public class XPathSaxon1 implements XPathSupport {
42:
43: public boolean isModelSupported(Node node) {
44: if (node instanceof NodeInfo)
45: return true;
46: return false;
47: }
48:
49: public List<Node> select(Node context, String xpath)
50: throws TransformerException {
51: List<Node> result;
52: result = new ArrayList<Node>();
53: NodeInfo cNode = (NodeInfo) context;
54: Expression exp = Expression
55: .make(xpath, new StandaloneContext());
56: Context ctx = new Context();
57: ctx.setContextNode(cNode);
58: ctx.setPosition(1);
59: ctx.setLast(1);
60: NodeSetValue nodeSet = exp.evaluateAsNodeSet(ctx);
61: NodeEnumeration enm = nodeSet.enumerate();
62: while (enm.hasMoreElements()) {
63: result.add((Node) enm.nextElement());
64: }
65: return result;
66: }
67:
68: public boolean test(Node context, String test)
69: throws TransformerException {
70: NodeInfo cNode = (NodeInfo) context;
71: Expression exp = Expression.make(test, new StandaloneContext());
72: Context ctx = new Context();
73: ctx.setContextNode(cNode);
74: ctx.setPosition(1);
75: ctx.setLast(1);
76: return exp.evaluateAsBoolean(ctx);
77: }
78:
79: }
|