OLD | NEW |
| (Empty) |
1 /* | |
2 * extra.c: Implementation of non-standard features | |
3 * | |
4 * Reference: | |
5 * Michael Kay "XSLT Programmer's Reference" pp 637-643 | |
6 * The node-set() extension function | |
7 * | |
8 * See Copyright for the status of this software. | |
9 * | |
10 * daniel@veillard.com | |
11 */ | |
12 | |
13 #define IN_LIBXSLT | |
14 #include "libxslt.h" | |
15 | |
16 #include <string.h> | |
17 #ifdef HAVE_STDLIB_H | |
18 #include <stdlib.h> | |
19 #endif | |
20 | |
21 #include <libxml/xmlmemory.h> | |
22 #include <libxml/tree.h> | |
23 #include <libxml/hash.h> | |
24 #include <libxml/xmlerror.h> | |
25 #include <libxml/parserInternals.h> | |
26 #include "xslt.h" | |
27 #include "xsltInternals.h" | |
28 #include "xsltutils.h" | |
29 #include "extensions.h" | |
30 #include "variables.h" | |
31 #include "transform.h" | |
32 #include "extra.h" | |
33 #include "preproc.h" | |
34 | |
35 #ifdef WITH_XSLT_DEBUG | |
36 #define WITH_XSLT_DEBUG_EXTRA | |
37 #endif | |
38 | |
39 /************************************************************************ | |
40 * * | |
41 * Handling of XSLT debugging * | |
42 * * | |
43 ************************************************************************/ | |
44 | |
45 /** | |
46 * xsltDebug: | |
47 * @ctxt: an XSLT processing context | |
48 * @node: The current node | |
49 * @inst: the instruction in the stylesheet | |
50 * @comp: precomputed informations | |
51 * | |
52 * Process an debug node | |
53 */ | |
54 void | |
55 xsltDebug(xsltTransformContextPtr ctxt, xmlNodePtr node ATTRIBUTE_UNUSED, | |
56 xmlNodePtr inst ATTRIBUTE_UNUSED, | |
57 xsltStylePreCompPtr comp ATTRIBUTE_UNUSED) | |
58 { | |
59 int i, j; | |
60 | |
61 xsltGenericError(xsltGenericErrorContext, "Templates:\n"); | |
62 for (i = 0, j = ctxt->templNr - 1; ((i < 15) && (j >= 0)); i++, j--) { | |
63 xsltGenericError(xsltGenericErrorContext, "#%d ", i); | |
64 if (ctxt->templTab[j]->name != NULL) | |
65 xsltGenericError(xsltGenericErrorContext, "name %s ", | |
66 ctxt->templTab[j]->name); | |
67 if (ctxt->templTab[j]->match != NULL) | |
68 xsltGenericError(xsltGenericErrorContext, "name %s ", | |
69 ctxt->templTab[j]->match); | |
70 if (ctxt->templTab[j]->mode != NULL) | |
71 xsltGenericError(xsltGenericErrorContext, "name %s ", | |
72 ctxt->templTab[j]->mode); | |
73 xsltGenericError(xsltGenericErrorContext, "\n"); | |
74 } | |
75 xsltGenericError(xsltGenericErrorContext, "Variables:\n"); | |
76 for (i = 0, j = ctxt->varsNr - 1; ((i < 15) && (j >= 0)); i++, j--) { | |
77 xsltStackElemPtr cur; | |
78 | |
79 if (ctxt->varsTab[j] == NULL) | |
80 continue; | |
81 xsltGenericError(xsltGenericErrorContext, "#%d\n", i); | |
82 cur = ctxt->varsTab[j]; | |
83 while (cur != NULL) { | |
84 if (cur->comp == NULL) { | |
85 xsltGenericError(xsltGenericErrorContext, | |
86 "corrupted !!!\n"); | |
87 } else if (cur->comp->type == XSLT_FUNC_PARAM) { | |
88 xsltGenericError(xsltGenericErrorContext, "param "); | |
89 } else if (cur->comp->type == XSLT_FUNC_VARIABLE) { | |
90 xsltGenericError(xsltGenericErrorContext, "var "); | |
91 } | |
92 if (cur->name != NULL) | |
93 xsltGenericError(xsltGenericErrorContext, "%s ", | |
94 cur->name); | |
95 else | |
96 xsltGenericError(xsltGenericErrorContext, "noname !!!!"); | |
97 #ifdef LIBXML_DEBUG_ENABLED | |
98 if (cur->value != NULL) { | |
99 xmlXPathDebugDumpObject(stdout, cur->value, 1); | |
100 } else { | |
101 xsltGenericError(xsltGenericErrorContext, "NULL !!!!"); | |
102 } | |
103 #endif | |
104 xsltGenericError(xsltGenericErrorContext, "\n"); | |
105 cur = cur->next; | |
106 } | |
107 | |
108 } | |
109 } | |
110 | |
111 /************************************************************************ | |
112 * * | |
113 * Classic extensions as described by M. Kay * | |
114 * * | |
115 ************************************************************************/ | |
116 | |
117 /** | |
118 * xsltFunctionNodeSet: | |
119 * @ctxt: the XPath Parser context | |
120 * @nargs: the number of arguments | |
121 * | |
122 * Implement the node-set() XSLT function | |
123 * node-set node-set(result-tree) | |
124 * | |
125 * This function is available in libxslt, saxon or xt namespace. | |
126 */ | |
127 void | |
128 xsltFunctionNodeSet(xmlXPathParserContextPtr ctxt, int nargs){ | |
129 if (nargs != 1) { | |
130 xsltTransformError(xsltXPathGetTransformContext(ctxt), NULL, NULL, | |
131 "node-set() : expects one result-tree arg\n"); | |
132 ctxt->error = XPATH_INVALID_ARITY; | |
133 return; | |
134 } | |
135 if ((ctxt->value == NULL) || | |
136 ((ctxt->value->type != XPATH_XSLT_TREE) && | |
137 (ctxt->value->type != XPATH_NODESET))) { | |
138 xsltTransformError(xsltXPathGetTransformContext(ctxt), NULL, NULL, | |
139 "node-set() invalid arg expecting a result tree\n"); | |
140 ctxt->error = XPATH_INVALID_TYPE; | |
141 return; | |
142 } | |
143 if (ctxt->value->type == XPATH_XSLT_TREE) { | |
144 ctxt->value->type = XPATH_NODESET; | |
145 } | |
146 } | |
147 | |
148 /** | |
149 * xsltRegisterExtras: | |
150 * @ctxt: a XSLT process context | |
151 * | |
152 * Registers the built-in extensions. This function is deprecated, use | |
153 * xsltRegisterAllExtras instead. | |
154 */ | |
155 void | |
156 xsltRegisterExtras(xsltTransformContextPtr ctxt ATTRIBUTE_UNUSED) { | |
157 xsltRegisterAllExtras(); | |
158 } | |
159 | |
160 /** | |
161 * xsltRegisterAllExtras: | |
162 * | |
163 * Registers the built-in extensions | |
164 */ | |
165 void | |
166 xsltRegisterAllExtras (void) { | |
167 xsltRegisterExtModuleFunction((const xmlChar *) "node-set", | |
168 XSLT_LIBXSLT_NAMESPACE, | |
169 xsltFunctionNodeSet); | |
170 xsltRegisterExtModuleFunction((const xmlChar *) "node-set", | |
171 XSLT_SAXON_NAMESPACE, | |
172 xsltFunctionNodeSet); | |
173 xsltRegisterExtModuleFunction((const xmlChar *) "node-set", | |
174 XSLT_XT_NAMESPACE, | |
175 xsltFunctionNodeSet); | |
176 xsltRegisterExtModuleElement((const xmlChar *) "debug", | |
177 XSLT_LIBXSLT_NAMESPACE, | |
178 NULL, | |
179 (xsltTransformFunction) xsltDebug); | |
180 xsltRegisterExtModuleElement((const xmlChar *) "output", | |
181 XSLT_SAXON_NAMESPACE, | |
182 xsltDocumentComp, | |
183 (xsltTransformFunction) xsltDocumentElem); | |
184 xsltRegisterExtModuleElement((const xmlChar *) "write", | |
185 XSLT_XALAN_NAMESPACE, | |
186 xsltDocumentComp, | |
187 (xsltTransformFunction) xsltDocumentElem); | |
188 xsltRegisterExtModuleElement((const xmlChar *) "document", | |
189 XSLT_XT_NAMESPACE, | |
190 xsltDocumentComp, | |
191 (xsltTransformFunction) xsltDocumentElem); | |
192 xsltRegisterExtModuleElement((const xmlChar *) "document", | |
193 XSLT_NAMESPACE, | |
194 xsltDocumentComp, | |
195 (xsltTransformFunction) xsltDocumentElem); | |
196 } | |
OLD | NEW |