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/xsltconfig.h>
15 #include <libxslt/xsltutils.h>
16 #include <libxslt/xsltInternals.h>
17 #include <libxslt/extensions.h>
18 #include <libxslt/transform.h>
19 #include <libxslt/extra.h>
20 #include <libxslt/preproc.h>
25 exsltNodeSetFunction (xmlXPathParserContextPtr ctxt
, int nargs
) {
27 xmlXPathSetArityError(ctxt
);
30 if (xmlXPathStackIsNodeSet (ctxt
)) {
31 xsltFunctionNodeSet (ctxt
, nargs
);
35 xsltTransformContextPtr tctxt
= xsltXPathGetTransformContext(ctxt
);
38 xmlXPathObjectPtr obj
;
41 * "You can also use this function to turn a string into a text
42 * node, which is helpful if you want to pass a string to a
43 * function that only accepts a node-set."
45 fragment
= xsltCreateRVT(tctxt
);
46 if (fragment
== NULL
) {
47 xsltTransformError(tctxt
, NULL
, tctxt
->inst
,
48 "exsltNodeSetFunction: Failed to create a tree fragment.\n");
49 tctxt
->state
= XSLT_STATE_STOPPED
;
52 xsltRegisterLocalRVT(tctxt
, fragment
);
54 strval
= xmlXPathPopString (ctxt
);
56 txt
= xmlNewDocText (fragment
, strval
);
57 xmlAddChild((xmlNodePtr
) fragment
, txt
);
58 obj
= xmlXPathNewNodeSet(txt
);
60 xsltTransformError(tctxt
, NULL
, tctxt
->inst
,
61 "exsltNodeSetFunction: Failed to create a node set object.\n");
62 tctxt
->state
= XSLT_STATE_STOPPED
;
65 * Mark it as a function result in order to avoid garbage
66 * collecting of tree fragments
68 xsltExtensionInstructionResultRegister(tctxt
, obj
);
73 valuePush (ctxt
, obj
);
78 exsltObjectTypeFunction (xmlXPathParserContextPtr ctxt
, int nargs
) {
79 xmlXPathObjectPtr obj
, ret
;
82 xmlXPathSetArityError(ctxt
);
90 ret
= xmlXPathNewCString("string");
93 ret
= xmlXPathNewCString("number");
96 ret
= xmlXPathNewCString("boolean");
99 ret
= xmlXPathNewCString("node-set");
101 case XPATH_XSLT_TREE
:
102 ret
= xmlXPathNewCString("RTF");
105 ret
= xmlXPathNewCString("external");
108 xsltGenericError(xsltGenericErrorContext
,
109 "object-type() invalid arg\n");
110 ctxt
->error
= XPATH_INVALID_TYPE
;
111 xmlXPathFreeObject(obj
);
114 xmlXPathFreeObject(obj
);
115 valuePush(ctxt
, ret
);
120 * exsltCommonRegister:
122 * Registers the EXSLT - Common module
126 exsltCommonRegister (void) {
127 xsltRegisterExtModuleFunction((const xmlChar
*) "node-set",
128 EXSLT_COMMON_NAMESPACE
,
129 exsltNodeSetFunction
);
130 xsltRegisterExtModuleFunction((const xmlChar
*) "object-type",
131 EXSLT_COMMON_NAMESPACE
,
132 exsltObjectTypeFunction
);
133 xsltRegisterExtModuleElement((const xmlChar
*) "document",
134 EXSLT_COMMON_NAMESPACE
,
135 (xsltPreComputeFunction
) xsltDocumentComp
,
136 (xsltTransformFunction
) xsltDocumentElem
);