VirtualBox

source: vbox/trunk/src/libs/libxslt-1.1.22/libexslt/common.c@ 22502

最後變更 在這個檔案從22502是 7299,由 vboxsync 提交於 17 年 前

Added vboxconfig.h for linux builds.

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Date Revision Author Id
檔案大小: 3.2 KB
 
1#define IN_LIBEXSLT
2#include "libexslt/libexslt.h"
3
4#if defined(WIN32) && !defined (__CYGWIN__) && (!__MINGW32__)
5#include <win32config.h>
6#elif defined(VBOX)
7#include "vboxconfig.h"
8#else
9#include "config.h"
10#endif
11
12#include <libxml/tree.h>
13#include <libxml/xpath.h>
14#include <libxml/xpathInternals.h>
15
16#include <libxslt/xsltconfig.h>
17#include <libxslt/xsltutils.h>
18#include <libxslt/xsltInternals.h>
19#include <libxslt/extensions.h>
20#include <libxslt/transform.h>
21#include <libxslt/extra.h>
22#include <libxslt/preproc.h>
23
24#include "exslt.h"
25
26static void
27exsltNodeSetFunction (xmlXPathParserContextPtr ctxt, int nargs) {
28 if (nargs != 1) {
29 xmlXPathSetArityError(ctxt);
30 return;
31 }
32 if (xmlXPathStackIsNodeSet (ctxt)) {
33 xsltFunctionNodeSet (ctxt, nargs);
34 return;
35 } else {
36 xmlDocPtr fragment;
37 xsltTransformContextPtr tctxt = xsltXPathGetTransformContext(ctxt);
38 xmlNodePtr txt;
39 xmlChar *strval;
40 xmlXPathObjectPtr obj;
41 /*
42 * SPEC EXSLT:
43 * "You can also use this function to turn a string into a text
44 * node, which is helpful if you want to pass a string to a
45 * function that only accepts a node-set."
46 */
47 fragment = xsltCreateRVT(tctxt);
48 if (fragment == NULL) {
49 xsltTransformError(tctxt, NULL, tctxt->inst,
50 "exsltNodeSetFunction: Failed to create a tree fragment.\n");
51 tctxt->state = XSLT_STATE_STOPPED;
52 return;
53 }
54 xsltRegisterLocalRVT(tctxt, fragment);
55
56 strval = xmlXPathPopString (ctxt);
57
58 txt = xmlNewDocText (fragment, strval);
59 xmlAddChild((xmlNodePtr) fragment, txt);
60 obj = xmlXPathNewNodeSet(txt);
61 if (obj == NULL) {
62 xsltTransformError(tctxt, NULL, tctxt->inst,
63 "exsltNodeSetFunction: Failed to create a node set object.\n");
64 tctxt->state = XSLT_STATE_STOPPED;
65 }
66 if (strval != NULL)
67 xmlFree (strval);
68
69 valuePush (ctxt, obj);
70 }
71}
72
73static void
74exsltObjectTypeFunction (xmlXPathParserContextPtr ctxt, int nargs) {
75 xmlXPathObjectPtr obj, ret;
76
77 if (nargs != 1) {
78 xmlXPathSetArityError(ctxt);
79 return;
80 }
81
82 obj = valuePop(ctxt);
83
84 switch (obj->type) {
85 case XPATH_STRING:
86 ret = xmlXPathNewCString("string");
87 break;
88 case XPATH_NUMBER:
89 ret = xmlXPathNewCString("number");
90 break;
91 case XPATH_BOOLEAN:
92 ret = xmlXPathNewCString("boolean");
93 break;
94 case XPATH_NODESET:
95 ret = xmlXPathNewCString("node-set");
96 break;
97 case XPATH_XSLT_TREE:
98 ret = xmlXPathNewCString("RTF");
99 break;
100 case XPATH_USERS:
101 ret = xmlXPathNewCString("external");
102 break;
103 default:
104 xsltGenericError(xsltGenericErrorContext,
105 "object-type() invalid arg\n");
106 ctxt->error = XPATH_INVALID_TYPE;
107 xmlXPathFreeObject(obj);
108 return;
109 }
110 xmlXPathFreeObject(obj);
111 valuePush(ctxt, ret);
112}
113
114
115/**
116 * exsltCommonRegister:
117 *
118 * Registers the EXSLT - Common module
119 */
120
121void
122exsltCommonRegister (void) {
123 xsltRegisterExtModuleFunction((const xmlChar *) "node-set",
124 EXSLT_COMMON_NAMESPACE,
125 exsltNodeSetFunction);
126 xsltRegisterExtModuleFunction((const xmlChar *) "object-type",
127 EXSLT_COMMON_NAMESPACE,
128 exsltObjectTypeFunction);
129 xsltRegisterExtModuleElement((const xmlChar *) "document",
130 EXSLT_COMMON_NAMESPACE,
131 (xsltPreComputeFunction) xsltDocumentComp,
132 (xsltTransformFunction) xsltDocumentElem);
133}
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette