2 #include "libexslt/libexslt.h"
4 #if defined(WIN32) && !defined (__CYGWIN__) && (!__MINGW32__)
5 #include <win32config.h>
10 #include <libxml/tree.h>
11 #include <libxml/xpath.h>
12 #include <libxml/xpathInternals.h>
14 #include <libxslt/xsltutils.h>
15 #include <libxslt/xsltInternals.h>
16 #include <libxslt/extensions.h>
21 * exsltSetsDifferenceFunction:
22 * @ctxt: an XPath parser context
23 * @nargs: the number of arguments
25 * Wraps #xmlXPathDifference for use by the XPath processor
28 exsltSetsDifferenceFunction (xmlXPathParserContextPtr ctxt
, int nargs
) {
29 xmlNodeSetPtr arg1
, arg2
, ret
;
32 xmlXPathSetArityError(ctxt
);
36 arg2
= xmlXPathPopNodeSet(ctxt
);
37 if (xmlXPathCheckError(ctxt
)) {
38 xmlXPathSetTypeError(ctxt
);
42 arg1
= xmlXPathPopNodeSet(ctxt
);
43 if (xmlXPathCheckError(ctxt
)) {
44 xmlXPathSetTypeError(ctxt
);
48 ret
= xmlXPathDifference(arg1
, arg2
);
51 xmlXPathFreeNodeSet(arg1
);
52 xmlXPathFreeNodeSet(arg2
);
54 xmlXPathReturnNodeSet(ctxt
, ret
);
58 * exsltSetsIntersectionFunction:
59 * @ctxt: an XPath parser context
60 * @nargs: the number of arguments
62 * Wraps #xmlXPathIntersection for use by the XPath processor
65 exsltSetsIntersectionFunction (xmlXPathParserContextPtr ctxt
, int nargs
) {
66 xmlNodeSetPtr arg1
, arg2
, ret
;
69 xmlXPathSetArityError(ctxt
);
73 arg2
= xmlXPathPopNodeSet(ctxt
);
74 if (xmlXPathCheckError(ctxt
)) {
75 xmlXPathSetTypeError(ctxt
);
79 arg1
= xmlXPathPopNodeSet(ctxt
);
80 if (xmlXPathCheckError(ctxt
)) {
81 xmlXPathSetTypeError(ctxt
);
85 ret
= xmlXPathIntersection(arg1
, arg2
);
87 xmlXPathFreeNodeSet(arg1
);
88 xmlXPathFreeNodeSet(arg2
);
90 xmlXPathReturnNodeSet(ctxt
, ret
);
94 * exsltSetsDistinctFunction:
95 * @ctxt: an XPath parser context
96 * @nargs: the number of arguments
98 * Wraps #xmlXPathDistinct for use by the XPath processor
101 exsltSetsDistinctFunction (xmlXPathParserContextPtr ctxt
, int nargs
) {
102 xmlXPathObjectPtr obj
;
103 xmlNodeSetPtr ns
, ret
;
108 xmlXPathSetArityError(ctxt
);
112 if (ctxt
->value
!= NULL
) {
113 boolval
= ctxt
->value
->boolval
;
114 user
= ctxt
->value
->user
;
115 ctxt
->value
->boolval
= 0;
116 ctxt
->value
->user
= NULL
;
118 ns
= xmlXPathPopNodeSet(ctxt
);
119 if (xmlXPathCheckError(ctxt
))
122 /* !!! must be sorted !!! */
123 ret
= xmlXPathDistinctSorted(ns
);
126 xmlXPathFreeNodeSet(ns
);
128 obj
= xmlXPathWrapNodeSet(ret
);
130 obj
->boolval
= boolval
;
131 valuePush((ctxt
), obj
);
135 * exsltSetsHasSameNodesFunction:
136 * @ctxt: an XPath parser context
137 * @nargs: the number of arguments
139 * Wraps #xmlXPathHasSameNodes for use by the XPath processor
142 exsltSetsHasSameNodesFunction (xmlXPathParserContextPtr ctxt
,
144 xmlNodeSetPtr arg1
, arg2
;
148 xmlXPathSetArityError(ctxt
);
152 arg2
= xmlXPathPopNodeSet(ctxt
);
153 if (xmlXPathCheckError(ctxt
)) {
154 xmlXPathSetTypeError(ctxt
);
158 arg1
= xmlXPathPopNodeSet(ctxt
);
159 if (xmlXPathCheckError(ctxt
)) {
160 xmlXPathSetTypeError(ctxt
);
164 ret
= xmlXPathHasSameNodes(arg1
, arg2
);
166 xmlXPathFreeNodeSet(arg1
);
167 xmlXPathFreeNodeSet(arg2
);
169 xmlXPathReturnBoolean(ctxt
, ret
);
173 * exsltSetsLeadingFunction:
174 * @ctxt: an XPath parser context
175 * @nargs: the number of arguments
177 * Wraps #xmlXPathLeading for use by the XPath processor
180 exsltSetsLeadingFunction (xmlXPathParserContextPtr ctxt
, int nargs
) {
181 xmlNodeSetPtr arg1
, arg2
, ret
;
184 xmlXPathSetArityError(ctxt
);
188 arg2
= xmlXPathPopNodeSet(ctxt
);
189 if (xmlXPathCheckError(ctxt
)) {
190 xmlXPathSetTypeError(ctxt
);
194 arg1
= xmlXPathPopNodeSet(ctxt
);
195 if (xmlXPathCheckError(ctxt
)) {
196 xmlXPathSetTypeError(ctxt
);
200 /* If the second node set is empty, then the first node set is
203 if (xmlXPathNodeSetIsEmpty(arg2
)) {
204 xmlXPathReturnNodeSet(ctxt
, arg1
);
206 xmlXPathFreeNodeSet(arg2
);
210 /* !!! must be sorted */
211 ret
= xmlXPathNodeLeadingSorted(arg1
, xmlXPathNodeSetItem(arg2
, 0));
213 xmlXPathFreeNodeSet(arg1
);
214 xmlXPathFreeNodeSet(arg2
);
216 xmlXPathReturnNodeSet(ctxt
, ret
);
220 * exsltSetsTrailingFunction:
221 * @ctxt: an XPath parser context
222 * @nargs: the number of arguments
224 * Wraps #xmlXPathTrailing for use by the XPath processor
227 exsltSetsTrailingFunction (xmlXPathParserContextPtr ctxt
, int nargs
) {
228 xmlNodeSetPtr arg1
, arg2
, ret
;
231 xmlXPathSetArityError(ctxt
);
235 arg2
= xmlXPathPopNodeSet(ctxt
);
236 if (xmlXPathCheckError(ctxt
)) {
237 xmlXPathSetTypeError(ctxt
);
241 arg1
= xmlXPathPopNodeSet(ctxt
);
242 if (xmlXPathCheckError(ctxt
)) {
243 xmlXPathSetTypeError(ctxt
);
247 /* If the second node set is empty, then the first node set is
250 if (xmlXPathNodeSetIsEmpty(arg2
)) {
251 xmlXPathReturnNodeSet(ctxt
, arg1
);
253 xmlXPathFreeNodeSet(arg2
);
257 /* !!! mist be sorted */
258 ret
= xmlXPathNodeTrailingSorted(arg1
, xmlXPathNodeSetItem(arg2
, 0));
260 xmlXPathFreeNodeSet(arg1
);
261 xmlXPathFreeNodeSet(arg2
);
263 xmlXPathReturnNodeSet(ctxt
, ret
);
269 * Registers the EXSLT - Sets module
273 exsltSetsRegister (void) {
274 xsltRegisterExtModuleFunction ((const xmlChar
*) "difference",
275 EXSLT_SETS_NAMESPACE
,
276 exsltSetsDifferenceFunction
);
277 xsltRegisterExtModuleFunction ((const xmlChar
*) "intersection",
278 EXSLT_SETS_NAMESPACE
,
279 exsltSetsIntersectionFunction
);
280 xsltRegisterExtModuleFunction ((const xmlChar
*) "distinct",
281 EXSLT_SETS_NAMESPACE
,
282 exsltSetsDistinctFunction
);
283 xsltRegisterExtModuleFunction ((const xmlChar
*) "has-same-node",
284 EXSLT_SETS_NAMESPACE
,
285 exsltSetsHasSameNodesFunction
);
286 xsltRegisterExtModuleFunction ((const xmlChar
*) "leading",
287 EXSLT_SETS_NAMESPACE
,
288 exsltSetsLeadingFunction
);
289 xsltRegisterExtModuleFunction ((const xmlChar
*) "trailing",
290 EXSLT_SETS_NAMESPACE
,
291 exsltSetsTrailingFunction
);
295 * exsltSetsXpathCtxtRegister:
297 * Registers the EXSLT - Sets module for use outside XSLT
300 exsltSetsXpathCtxtRegister (xmlXPathContextPtr ctxt
, const xmlChar
*prefix
)
304 && !xmlXPathRegisterNs(ctxt
,
306 (const xmlChar
*) EXSLT_SETS_NAMESPACE
)
307 && !xmlXPathRegisterFuncNS(ctxt
,
308 (const xmlChar
*) "difference",
309 (const xmlChar
*) EXSLT_SETS_NAMESPACE
,
310 exsltSetsDifferenceFunction
)
311 && !xmlXPathRegisterFuncNS(ctxt
,
312 (const xmlChar
*) "intersection",
313 (const xmlChar
*) EXSLT_SETS_NAMESPACE
,
314 exsltSetsIntersectionFunction
)
315 && !xmlXPathRegisterFuncNS(ctxt
,
316 (const xmlChar
*) "distinct",
317 (const xmlChar
*) EXSLT_SETS_NAMESPACE
,
318 exsltSetsDistinctFunction
)
319 && !xmlXPathRegisterFuncNS(ctxt
,
320 (const xmlChar
*) "has-same-node",
321 (const xmlChar
*) EXSLT_SETS_NAMESPACE
,
322 exsltSetsHasSameNodesFunction
)
323 && !xmlXPathRegisterFuncNS(ctxt
,
324 (const xmlChar
*) "leading",
325 (const xmlChar
*) EXSLT_SETS_NAMESPACE
,
326 exsltSetsLeadingFunction
)
327 && !xmlXPathRegisterFuncNS(ctxt
,
328 (const xmlChar
*) "trailing",
329 (const xmlChar
*) EXSLT_SETS_NAMESPACE
,
330 exsltSetsTrailingFunction
)) {