2 * imports.c: Implementation of the XSLT imports
5 * http://www.w3.org/TR/1999/REC-xslt-19991116
7 * See Copyright for the status of this software.
9 * Daniel.Veillard@imag.fr
12 #include "xsltconfig.h"
16 #ifdef HAVE_SYS_TYPES_H
17 #include <sys/types.h>
35 #include <libxml/xmlmemory.h>
36 #include <libxml/tree.h>
37 #include <libxml/hash.h>
38 #include <libxml/xmlerror.h>
39 #include <libxml/uri.h>
41 #include "xsltInternals.h"
42 #include "xsltutils.h"
47 /************************************************************************
51 ************************************************************************/
54 * xsltParseStylesheetImport:
55 * @style: the XSLT stylesheet
56 * @template: the "strip-space" element
58 * parse an XSLT stylesheet strip-space element and record
59 * elements needing stripping
63 xsltParseStylesheetImport(xsltStylesheetPtr style, xmlNodePtr cur) {
64 xmlDocPtr import = NULL;
66 xmlChar *uriRef = NULL;
68 xsltStylesheetPtr res;
70 if ((cur == NULL) || (style == NULL))
73 uriRef = xmlGetNsProp(cur, (const xmlChar *)"href", XSLT_NAMESPACE);
75 xsltGenericError(xsltGenericErrorContext,
76 "xsl:import : missing href attribute\n");
80 base = xmlNodeGetBase(style->doc, cur);
81 URI = xmlBuildURI(uriRef, base);
83 xsltGenericError(xsltGenericErrorContext,
84 "xsl:import : invalid URI reference %s\n", uriRef);
87 import = xmlParseFile((const char *)URI);
89 xsltGenericError(xsltGenericErrorContext,
90 "xsl:import : unable to load %s\n", URI);
94 res = xsltParseStylesheetDoc(import);
97 res->next = style->imports;
111 * xsltParseStylesheetInclude:
112 * @style: the XSLT stylesheet
113 * @template: the "strip-space" element
115 * parse an XSLT stylesheet strip-space element and record
116 * elements needing stripping
120 xsltParseStylesheetInclude(xsltStylesheetPtr style, xmlNodePtr cur) {
121 xmlDocPtr include = NULL, oldDoc;
122 xmlChar *base = NULL;
123 xmlChar *uriRef = NULL;
126 if ((cur == NULL) || (style == NULL))
129 uriRef = xmlGetNsProp(cur, (const xmlChar *)"href", XSLT_NAMESPACE);
130 if (uriRef == NULL) {
131 xsltGenericError(xsltGenericErrorContext,
132 "xsl:include : missing href attribute\n");
136 base = xmlNodeGetBase(style->doc, cur);
137 URI = xmlBuildURI(uriRef, base);
139 xsltGenericError(xsltGenericErrorContext,
140 "xsl:include : invalid URI reference %s\n", uriRef);
143 include = xmlParseFile((const char *)URI);
144 if (include == NULL) {
145 xsltGenericError(xsltGenericErrorContext,
146 "xsl:include : unable to load %s\n", URI);
151 style->doc = include;
152 xsltParseStylesheetProcess(style, include);
166 * @cur: the current XSLT stylesheet
168 * Find the next stylesheet in import precedence.
170 * Returns the next stylesheet or NULL if it was the last one
174 xsltNextImport(xsltStylesheetPtr cur) {
177 if (cur->imports != NULL)
178 return(cur->imports);
179 if (cur->next != NULL)
183 if (cur == NULL) return(NULL);
184 if (cur->next != NULL) return(cur->next);
185 } while (cur != NULL);
190 * xsltFindElemSpaceHandling:
191 * ctxt: an XSLT transformation context
194 * Find strip-space or preserve-space informations for an element
195 * respect the import precedence or the wildcards
197 * Returns 1 if space should be stripped, 0 if not, and 2 if everything
198 * should be CDTATA wrapped.
202 xsltFindElemSpaceHandling(xsltTransformContextPtr ctxt, xmlNodePtr node) {
203 xsltStylesheetPtr style;
206 if ((ctxt == NULL) || (node == NULL))
209 while (style != NULL) {
210 /* TODO: add namespaces support */
211 val = (const xmlChar *)
212 xmlHashLookup(style->stripSpaces, node->name);
214 if (xmlStrEqual(val, (xmlChar *) "strip"))
216 if (xmlStrEqual(val, (xmlChar *) "preserve"))
219 val = (const xmlChar *)
220 xmlHashLookup(ctxt->style->stripSpaces,
221 (const xmlChar *)"*");
223 (xmlStrEqual(val, (xmlChar *) "strip")))
225 if (xmlStrEqual(val, (xmlChar *) "preserve"))
228 style = xsltNextImport(style);
235 * ctxt: an XSLT transformation context
236 * @name: the template name
237 * @nameURI: the template name URI
239 * Finds the named template, apply import precedence rule.
241 * Returns the xsltTemplatePtr or NULL if not found
244 xsltFindTemplate(xsltTransformContextPtr ctxt, const xmlChar *name,
245 const xmlChar *nameURI) {
247 xsltStylesheetPtr style;
249 if ((ctxt == NULL) || (name == NULL))
252 while (style != NULL) {
253 cur = style->templates;
254 while (cur != NULL) {
255 if (xmlStrEqual(name, cur->name)) {
256 if (((nameURI == NULL) && (cur->nameURI == NULL)) ||
257 ((nameURI != NULL) && (cur->nameURI != NULL) &&
258 (xmlStrEqual(nameURI, cur->nameURI)))) {
265 style = xsltNextImport(style);