* @template: the "strip-space" element
*
* parse an XSLT stylesheet strip-space element and record
- * elements needing stripping
+ * elements needing stripping. Returns zero on success and something else
+ * on failure.
*/
-void
+int
xsltParseStylesheetImport(xsltStylesheetPtr style, xmlNodePtr cur) {
+ int ret = -1;
xmlDocPtr import = NULL;
xmlChar *base = NULL;
xmlChar *uriRef = NULL;
xsltStylesheetPtr res;
if ((cur == NULL) || (style == NULL))
- return;
+ return (ret);
uriRef = xsltGetNsProp(cur, (const xmlChar *)"href", XSLT_NAMESPACE);
if (uriRef == NULL) {
res->next = style->imports;
style->imports = res;
style->extrasNr += res->extrasNr;
- }
+ ret = 0;
+ } else {
+ xmlFreeDoc(import);
+ }
error:
if (uriRef != NULL)
xmlFree(base);
if (URI != NULL)
xmlFree(URI);
+
+ return (ret);
}
/**
* @template: the "strip-space" element
*
* parse an XSLT stylesheet strip-space element and record
- * elements needing stripping
+ * elements needing stripping. Returns zero on success, something else
+ * on failure.
*/
-void
+int
xsltParseStylesheetInclude(xsltStylesheetPtr style, xmlNodePtr cur) {
+ int ret = -1;
xmlDocPtr oldDoc;
xmlChar *base = NULL;
xmlChar *uriRef = NULL;
xsltDocumentPtr include;
if ((cur == NULL) || (style == NULL))
- return;
+ return (ret);
uriRef = xsltGetNsProp(cur, (const xmlChar *)"href", XSLT_NAMESPACE);
if (uriRef == NULL) {
oldDoc = style->doc;
style->doc = include->doc;
- xsltParseStylesheetProcess(style, include->doc);
+ ret = (int)xsltParseStylesheetProcess(style, include->doc);
style->doc = oldDoc;
+ if (ret == 0) {
+ ret = -1;
+ goto error;
+ }
+ ret = 0;
error:
if (uriRef != NULL)
xmlFree(base);
if (URI != NULL)
xmlFree(URI);
+
+ return (ret);
}
/**
/*
* process xsl:import elements
*/
- while (cur != NULL) {
- if (IS_BLANK_NODE(cur)) {
- cur = cur->next;
- continue;
+ while (cur != NULL) {
+ if (IS_BLANK_NODE(cur)) {
+ cur = cur->next;
+ continue;
+ }
+ if (IS_XSLT_ELEM(cur) && IS_XSLT_NAME(cur, "import")) {
+ if (xsltParseStylesheetImport(style, cur) != 0)
+ style->errors++;
+ } else
+ break;
+ cur = cur->next;
}
- if (IS_XSLT_ELEM(cur) && IS_XSLT_NAME(cur, "import")) {
- xsltParseStylesheetImport(style, cur);
- } else
- break;
- cur = cur->next;
- }
/*
* process other top-level elements
*/
if (IS_XSLT_NAME(cur, "import")) {
xsltPrintErrorContext(NULL, style, cur);
xsltGenericError(xsltGenericErrorContext,
- "xsltParseStylesheetTop: ignoring misplaced import element\n");
+ "xsltParseStylesheetTop: ignoring misplaced import element\n");
style->errors++;
- } else if (IS_XSLT_NAME(cur, "include")) {
- xsltParseStylesheetInclude(style, cur);
- } else if (IS_XSLT_NAME(cur, "strip-space")) {
+ } else if (IS_XSLT_NAME(cur, "include")) {
+ if (xsltParseStylesheetInclude(style, cur) != 0)
+ style->errors++;
+ } else if (IS_XSLT_NAME(cur, "strip-space")) {
xsltParseStylesheetStripSpace(style, cur);
- } else if (IS_XSLT_NAME(cur, "preserve-space")) {
+ } else if (IS_XSLT_NAME(cur, "preserve-space")) {
xsltParseStylesheetPreserveSpace(style, cur);
- } else if (IS_XSLT_NAME(cur, "output")) {
+ } else if (IS_XSLT_NAME(cur, "output")) {
xsltParseStylesheetOutput(style, cur);
- } else if (IS_XSLT_NAME(cur, "key")) {
+ } else if (IS_XSLT_NAME(cur, "key")) {
xsltParseStylesheetKey(style, cur);
- } else if (IS_XSLT_NAME(cur, "decimal-format")) {
+ } else if (IS_XSLT_NAME(cur, "decimal-format")) {
xsltParseStylesheetDecimalFormat(style, cur);
- } else if (IS_XSLT_NAME(cur, "attribute-set")) {
+ } else if (IS_XSLT_NAME(cur, "attribute-set")) {
xsltParseStylesheetAttributeSet(style, cur);
- } else if (IS_XSLT_NAME(cur, "variable")) {
+ } else if (IS_XSLT_NAME(cur, "variable")) {
xsltParseGlobalVariable(style, cur);
- } else if (IS_XSLT_NAME(cur, "param")) {
+ } else if (IS_XSLT_NAME(cur, "param")) {
xsltParseGlobalParam(style, cur);
- } else if (IS_XSLT_NAME(cur, "template")) {
+ } else if (IS_XSLT_NAME(cur, "template")) {
#ifdef WITH_XSLT_DEBUG_PARSING
templates++;
#endif
xsltParseStylesheetTemplate(style, cur);
- } else if (IS_XSLT_NAME(cur, "namespace-alias")) {
+ } else if (IS_XSLT_NAME(cur, "namespace-alias")) {
xsltNamespaceAlias(style, cur);
} else {
xsltPrintErrorContext(NULL, style, cur);
xsltGenericError(xsltGenericErrorContext,
- "xsltParseStylesheetTop: ignoring unknown %s element\n",
- cur->name);
+ "xsltParseStylesheetTop: ignoring unknown %s element\n",
+ cur->name);
style->warnings++;
}
cur = cur->next;
*
* parse an XSLT stylesheet adding the associated structures
*
- * Returns a new XSLT stylesheet structure.
+ * Returns the value of the 'ret' parameter if everything
+ * went right, NULL if something went amiss.
*/
xsltStylesheetPtr
xsltPrintErrorContext(NULL, ret, (xmlNodePtr) doc);
xsltGenericError(xsltGenericErrorContext,
"xsltParseStylesheetProcess : empty stylesheet\n");
- ret->doc = NULL;
- xsltFreeStylesheet(ret);
return(NULL);
}
xsltParseStylesheetExcludePrefix(ret, cur);
xsltPrintErrorContext(NULL, ret, cur);
xsltGenericError(xsltGenericErrorContext,
"xsltParseStylesheetProcess : document is not a stylesheet\n");
- ret->doc = NULL;
- xsltFreeStylesheet(ret);
return(NULL);
}
*/
template = xsltNewTemplate();
if (template == NULL) {
- ret->doc = NULL;
- xsltFreeStylesheet(ret);
return(NULL);
}
template->next = ret->templates;
ret->doc = doc;
xsltGatherNamespaces(ret);
- ret = xsltParseStylesheetProcess(ret, doc);
+ if (xsltParseStylesheetProcess(ret, doc) == NULL) {
+ ret->doc = NULL;
+ xsltFreeStylesheet(ret);
+ ret = NULL;
+ }
return(ret);
}