2 * extra.c: Implementation of non-standard features
5 * Michael Kay "XSLT Programmer's Reference" pp 637-643
6 * The node-set() extension function
8 * See Copyright for the status of this software.
15 #ifdef WITH_XSLT_DEBUG
16 #define WITH_XSLT_DEBUG_EXTRA
19 /************************************************************************
21 * Handling of XSLT debugging *
23 ************************************************************************/
27 * @ctxt: an XSLT processing context
28 * @node: The current node
29 * @inst: the instruction in the stylesheet
30 * @comp: precomputed informations
32 * Process an debug node
35 xsltDebug(xsltTransformContextPtr ctxt
, xmlNodePtr node ATTRIBUTE_UNUSED
,
36 xmlNodePtr inst ATTRIBUTE_UNUSED
,
37 xsltStylePreCompPtr comp ATTRIBUTE_UNUSED
)
41 xsltGenericError(xsltGenericErrorContext
, "Templates:\n");
42 for (i
= 0, j
= ctxt
->templNr
- 1; ((i
< 15) && (j
>= 0)); i
++, j
--) {
43 xsltGenericError(xsltGenericErrorContext
, "#%d ", i
);
44 if (ctxt
->templTab
[j
]->name
!= NULL
)
45 xsltGenericError(xsltGenericErrorContext
, "name %s ",
46 ctxt
->templTab
[j
]->name
);
47 if (ctxt
->templTab
[j
]->match
!= NULL
)
48 xsltGenericError(xsltGenericErrorContext
, "name %s ",
49 ctxt
->templTab
[j
]->match
);
50 if (ctxt
->templTab
[j
]->mode
!= NULL
)
51 xsltGenericError(xsltGenericErrorContext
, "name %s ",
52 ctxt
->templTab
[j
]->mode
);
53 xsltGenericError(xsltGenericErrorContext
, "\n");
55 xsltGenericError(xsltGenericErrorContext
, "Variables:\n");
56 for (i
= 0, j
= ctxt
->varsNr
- 1; ((i
< 15) && (j
>= 0)); i
++, j
--) {
59 if (ctxt
->varsTab
[j
] == NULL
)
61 xsltGenericError(xsltGenericErrorContext
, "#%d\n", i
);
62 cur
= ctxt
->varsTab
[j
];
64 if (cur
->comp
== NULL
) {
65 xsltGenericError(xsltGenericErrorContext
,
67 } else if (cur
->comp
->type
== XSLT_FUNC_PARAM
) {
68 xsltGenericError(xsltGenericErrorContext
, "param ");
69 } else if (cur
->comp
->type
== XSLT_FUNC_VARIABLE
) {
70 xsltGenericError(xsltGenericErrorContext
, "var ");
72 if (cur
->name
!= NULL
)
73 xsltGenericError(xsltGenericErrorContext
, "%s ",
76 xsltGenericError(xsltGenericErrorContext
, "noname !!!!");
77 #ifdef LIBXML_DEBUG_ENABLED
78 if (cur
->value
!= NULL
) {
79 if ((xsltGenericDebugContext
== stdout
) ||
80 (xsltGenericDebugContext
== stderr
))
81 xmlXPathDebugDumpObject((FILE*)xsltGenericDebugContext
,
84 xsltGenericError(xsltGenericErrorContext
, "NULL !!!!");
87 xsltGenericError(xsltGenericErrorContext
, "\n");
94 /************************************************************************
96 * Classic extensions as described by M. Kay *
98 ************************************************************************/
101 * xsltFunctionNodeSet:
102 * @ctxt: the XPath Parser context
103 * @nargs: the number of arguments
105 * Implement the node-set() XSLT function
106 * node-set node-set(result-tree)
108 * This function is available in libxslt, saxon or xt namespace.
111 xsltFunctionNodeSet(xmlXPathParserContextPtr ctxt
, int nargs
){
113 xsltTransformError(xsltXPathGetTransformContext(ctxt
), NULL
, NULL
,
114 "node-set() : expects one result-tree arg\n");
115 ctxt
->error
= XPATH_INVALID_ARITY
;
118 if ((ctxt
->value
== NULL
) ||
119 ((ctxt
->value
->type
!= XPATH_XSLT_TREE
) &&
120 (ctxt
->value
->type
!= XPATH_NODESET
))) {
121 xsltTransformError(xsltXPathGetTransformContext(ctxt
), NULL
, NULL
,
122 "node-set() invalid arg expecting a result tree\n");
123 ctxt
->error
= XPATH_INVALID_TYPE
;
126 if (ctxt
->value
->type
== XPATH_XSLT_TREE
) {
127 ctxt
->value
->type
= XPATH_NODESET
;
132 * xsltRegisterExtras:
133 * @ctxt: a XSLT process context
135 * Registers the built-in extensions. This function is deprecated, use
136 * xsltRegisterAllExtras instead.
139 xsltRegisterExtras(xsltTransformContextPtr ctxt ATTRIBUTE_UNUSED
) {
140 xsltRegisterAllExtras();
144 * xsltRegisterAllExtras:
146 * Registers the built-in extensions
149 xsltRegisterAllExtras (void) {
150 xsltRegisterExtModuleFunction((const xmlChar
*) "node-set",
151 XSLT_LIBXSLT_NAMESPACE
,
152 xsltFunctionNodeSet
);
153 xsltRegisterExtModuleFunction((const xmlChar
*) "node-set",
154 XSLT_SAXON_NAMESPACE
,
155 xsltFunctionNodeSet
);
156 xsltRegisterExtModuleFunction((const xmlChar
*) "node-set",
158 xsltFunctionNodeSet
);
159 xsltRegisterExtModuleElement((const xmlChar
*) "debug",
160 XSLT_LIBXSLT_NAMESPACE
,
162 (xsltTransformFunction
) xsltDebug
);
163 xsltRegisterExtModuleElement((const xmlChar
*) "output",
164 XSLT_SAXON_NAMESPACE
,
166 (xsltTransformFunction
) xsltDocumentElem
);
167 xsltRegisterExtModuleElement((const xmlChar
*) "write",
168 XSLT_XALAN_NAMESPACE
,
170 (xsltTransformFunction
) xsltDocumentElem
);
171 xsltRegisterExtModuleElement((const xmlChar
*) "document",
174 (xsltTransformFunction
) xsltDocumentElem
);
175 xsltRegisterExtModuleElement((const xmlChar
*) "document",
178 (xsltTransformFunction
) xsltDocumentElem
);