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;
113 * xsltParseStylesheetInclude:
114 * @style: the XSLT stylesheet
115 * @template: the "strip-space" element
117 * parse an XSLT stylesheet strip-space element and record
118 * elements needing stripping
122 xsltParseStylesheetInclude(xsltStylesheetPtr style, xmlNodePtr cur) {
123 xmlDocPtr include = NULL, oldDoc;
124 xmlChar *base = NULL;
125 xmlChar *uriRef = NULL;
128 if ((cur == NULL) || (style == NULL))
131 uriRef = xmlGetNsProp(cur, (const xmlChar *)"href", XSLT_NAMESPACE);
132 if (uriRef == NULL) {
133 xsltGenericError(xsltGenericErrorContext,
134 "xsl:include : missing href attribute\n");
138 base = xmlNodeGetBase(style->doc, cur);
139 URI = xmlBuildURI(uriRef, base);
141 xsltGenericError(xsltGenericErrorContext,
142 "xsl:include : invalid URI reference %s\n", uriRef);
145 include = xmlParseFile((const char *)URI);
146 if (include == NULL) {
147 xsltGenericError(xsltGenericErrorContext,
148 "xsl:include : unable to load %s\n", URI);
153 style->doc = include;
154 xsltParseStylesheetProcess(style, include);
170 * @cur: the current XSLT stylesheet
172 * Find the next stylesheet in import precedence.
174 * Returns the next stylesheet or NULL if it was the last one
178 xsltNextImport(xsltStylesheetPtr cur) {
181 if (cur->imports != NULL)
182 return(cur->imports);
183 if (cur->next != NULL)
187 if (cur == NULL) return(NULL);
188 if (cur->next != NULL) return(cur->next);
189 } while (cur != NULL);
194 * xsltFindElemSpaceHandling:
195 * ctxt: an XSLT transformation context
198 * Find strip-space or preserve-space informations for an element
199 * respect the import precedence or the wildcards
201 * Returns 1 if space should be stripped, 0 if not, and 2 if everything
202 * should be CDTATA wrapped.
206 xsltFindElemSpaceHandling(xsltTransformContextPtr ctxt, xmlNodePtr node) {
207 xsltStylesheetPtr style;
210 if ((ctxt == NULL) || (node == NULL))
213 while (style != NULL) {
214 /* TODO: add namespaces support */
215 val = (const xmlChar *)
216 xmlHashLookup(style->stripSpaces, node->name);
218 if (xmlStrEqual(val, (xmlChar *) "strip"))
220 if (xmlStrEqual(val, (xmlChar *) "preserve"))
223 val = (const xmlChar *)
224 xmlHashLookup(ctxt->style->stripSpaces,
225 (const xmlChar *)"*");
227 (xmlStrEqual(val, (xmlChar *) "strip")))
229 if (xmlStrEqual(val, (xmlChar *) "preserve"))
232 style = xsltNextImport(style);
239 * ctxt: an XSLT transformation context
240 * @name: the template name
241 * @nameURI: the template name URI
243 * Finds the named template, apply import precedence rule.
245 * Returns the xsltTemplatePtr or NULL if not found
248 xsltFindTemplate(xsltTransformContextPtr ctxt, const xmlChar *name,
249 const xmlChar *nameURI) {
251 xsltStylesheetPtr style;
253 if ((ctxt == NULL) || (name == NULL))
256 while (style != NULL) {
257 cur = style->templates;
258 while (cur != NULL) {
259 if (xmlStrEqual(name, cur->name)) {
260 if (((nameURI == NULL) && (cur->nameURI == NULL)) ||
261 ((nameURI != NULL) && (cur->nameURI != NULL) &&
262 (xmlStrEqual(nameURI, cur->nameURI)))) {
269 style = xsltNextImport(style);