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