1 #include "libexslt/libexslt.h"
3 #if defined(WIN32) && !defined (__CYGWIN__)
4 #include <win32config.h>
9 #include <libxml/tree.h>
10 #include <libxml/xpath.h>
11 #include <libxml/xpathInternals.h>
13 #include <libxslt/xsltutils.h>
14 #include <libxslt/xsltInternals.h>
15 #include <libxslt/extensions.h>
20 * exsltSetsDifferenceFunction:
21 * @ctxt: an XPath parser context
22 * @nargs: the number of arguments
24 * Wraps #xmlXPathDifference for use by the XPath processor
27 exsltSetsDifferenceFunction (xmlXPathParserContextPtr ctxt, int nargs) {
28 xmlNodeSetPtr arg1, arg2, ret;
31 xmlXPathSetArityError(ctxt);
35 arg2 = xmlXPathPopNodeSet(ctxt);
36 if (xmlXPathCheckError(ctxt)) {
37 xmlXPathSetTypeError(ctxt);
41 arg1 = xmlXPathPopNodeSet(ctxt);
42 if (xmlXPathCheckError(ctxt)) {
43 xmlXPathSetTypeError(ctxt);
47 ret = xmlXPathDifference(arg1, arg2);
50 xmlXPathFreeNodeSet(arg1);
51 xmlXPathFreeNodeSet(arg2);
53 xmlXPathReturnNodeSet(ctxt, ret);
57 * exsltSetsIntersectionFunction:
58 * @ctxt: an XPath parser context
59 * @nargs: the number of arguments
61 * Wraps #xmlXPathIntersection for use by the XPath processor
64 exsltSetsIntersectionFunction (xmlXPathParserContextPtr ctxt, int nargs) {
65 xmlNodeSetPtr arg1, arg2, ret;
68 xmlXPathSetArityError(ctxt);
72 arg2 = xmlXPathPopNodeSet(ctxt);
73 if (xmlXPathCheckError(ctxt)) {
74 xmlXPathSetTypeError(ctxt);
78 arg1 = xmlXPathPopNodeSet(ctxt);
79 if (xmlXPathCheckError(ctxt)) {
80 xmlXPathSetTypeError(ctxt);
84 ret = xmlXPathIntersection(arg1, arg2);
86 xmlXPathFreeNodeSet(arg1);
87 xmlXPathFreeNodeSet(arg2);
89 xmlXPathReturnNodeSet(ctxt, ret);
93 * exsltSetsDistinctFunction:
94 * @ctxt: an XPath parser context
95 * @nargs: the number of arguments
97 * Wraps #xmlXPathDistinct for use by the XPath processor
100 exsltSetsDistinctFunction (xmlXPathParserContextPtr ctxt, int nargs) {
101 xmlNodeSetPtr ns, ret;
104 xmlXPathSetArityError(ctxt);
108 ns = xmlXPathPopNodeSet(ctxt);
109 if (xmlXPathCheckError(ctxt))
112 /* !!! must be sorted !!! */
113 ret = xmlXPathDistinctSorted(ns);
115 xmlXPathFreeNodeSet(ns);
117 xmlXPathReturnNodeSet(ctxt, ret);
121 * exsltSetsHasSameNodesFunction:
122 * @ctxt: an XPath parser context
123 * @nargs: the number of arguments
125 * Wraps #xmlXPathHasSameNodes for use by the XPath processor
128 exsltSetsHasSameNodesFunction (xmlXPathParserContextPtr ctxt,
130 xmlNodeSetPtr arg1, arg2;
134 xmlXPathSetArityError(ctxt);
138 arg2 = xmlXPathPopNodeSet(ctxt);
139 if (xmlXPathCheckError(ctxt)) {
140 xmlXPathSetTypeError(ctxt);
144 arg1 = xmlXPathPopNodeSet(ctxt);
145 if (xmlXPathCheckError(ctxt)) {
146 xmlXPathSetTypeError(ctxt);
150 ret = xmlXPathHasSameNodes(arg1, arg2);
152 xmlXPathFreeNodeSet(arg1);
153 xmlXPathFreeNodeSet(arg2);
155 xmlXPathReturnBoolean(ctxt, ret);
159 * exsltSetsLeadingFunction:
160 * @ctxt: an XPath parser context
161 * @nargs: the number of arguments
163 * Wraps #xmlXPathLeading for use by the XPath processor
166 exsltSetsLeadingFunction (xmlXPathParserContextPtr ctxt, int nargs) {
167 xmlNodeSetPtr arg1, arg2, ret;
170 xmlXPathSetArityError(ctxt);
174 arg2 = xmlXPathPopNodeSet(ctxt);
175 if (xmlXPathCheckError(ctxt)) {
176 xmlXPathSetTypeError(ctxt);
180 arg1 = xmlXPathPopNodeSet(ctxt);
181 if (xmlXPathCheckError(ctxt)) {
182 xmlXPathSetTypeError(ctxt);
186 /* If the second node set is empty, then the first node set is
189 if (xmlXPathNodeSetIsEmpty(arg2)) {
190 xmlXPathReturnNodeSet(ctxt, arg1);
192 xmlXPathFreeNodeSet(arg2);
196 /* !!! must be sorted */
197 ret = xmlXPathNodeLeadingSorted(arg1, xmlXPathNodeSetItem(arg2, 0));
199 xmlXPathFreeNodeSet(arg1);
200 xmlXPathFreeNodeSet(arg2);
202 xmlXPathReturnNodeSet(ctxt, ret);
206 * exsltSetsTrailingFunction:
207 * @ctxt: an XPath parser context
208 * @nargs: the number of arguments
210 * Wraps #xmlXPathTrailing for use by the XPath processor
213 exsltSetsTrailingFunction (xmlXPathParserContextPtr ctxt, int nargs) {
214 xmlNodeSetPtr arg1, arg2, ret;
217 xmlXPathSetArityError(ctxt);
221 arg2 = xmlXPathPopNodeSet(ctxt);
222 if (xmlXPathCheckError(ctxt)) {
223 xmlXPathSetTypeError(ctxt);
227 arg1 = xmlXPathPopNodeSet(ctxt);
228 if (xmlXPathCheckError(ctxt)) {
229 xmlXPathSetTypeError(ctxt);
233 /* If the second node set is empty, then the first node set is
236 if (xmlXPathNodeSetIsEmpty(arg2)) {
237 xmlXPathReturnNodeSet(ctxt, arg1);
239 xmlXPathFreeNodeSet(arg2);
243 /* !!! mist be sorted */
244 ret = xmlXPathNodeTrailingSorted(arg1, xmlXPathNodeSetItem(arg2, 0));
246 xmlXPathFreeNodeSet(arg1);
247 xmlXPathFreeNodeSet(arg2);
249 xmlXPathReturnNodeSet(ctxt, ret);
255 * Registers the EXSLT - Sets module
259 exsltSetsRegister (void) {
260 xsltRegisterExtModuleFunction ((const xmlChar *) "difference",
261 EXSLT_SETS_NAMESPACE,
262 exsltSetsDifferenceFunction);
263 xsltRegisterExtModuleFunction ((const xmlChar *) "intersection",
264 EXSLT_SETS_NAMESPACE,
265 exsltSetsIntersectionFunction);
266 xsltRegisterExtModuleFunction ((const xmlChar *) "distinct",
267 EXSLT_SETS_NAMESPACE,
268 exsltSetsDistinctFunction);
269 xsltRegisterExtModuleFunction ((const xmlChar *) "has-same-node",
270 EXSLT_SETS_NAMESPACE,
271 exsltSetsHasSameNodesFunction);
272 xsltRegisterExtModuleFunction ((const xmlChar *) "leading",
273 EXSLT_SETS_NAMESPACE,
274 exsltSetsLeadingFunction);
275 xsltRegisterExtModuleFunction ((const xmlChar *) "trailing",
276 EXSLT_SETS_NAMESPACE,
277 exsltSetsTrailingFunction);