diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | libxslt/pattern.c | 12 | ||||
-rw-r--r-- | libxslt/templates.c | 10 | ||||
-rw-r--r-- | libxslt/transform.c | 127 | ||||
-rw-r--r-- | tests/REC/test-7.3.out | 2 | ||||
-rw-r--r-- | tests/REC/test-7.3.xml | 2 | ||||
-rw-r--r-- | tests/REC/test-7.3.xsl | 15 | ||||
-rw-r--r-- | tests/REC/test-7.4.out | 2 | ||||
-rw-r--r-- | tests/REC/test-7.4.xml | 2 | ||||
-rw-r--r-- | tests/REC/test-7.4.xsl | 15 | ||||
-rw-r--r-- | tests/REC/test-7.5-1.out | 4 | ||||
-rw-r--r-- | tests/REC/test-7.5-1.xml | 3 | ||||
-rw-r--r-- | tests/REC/test-7.5-1.xsl | 12 |
13 files changed, 188 insertions, 24 deletions
@@ -1,3 +1,9 @@ +Wed Jan 31 14:25:25 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr> + + * tests/REC/test-7.*: added more tests + * libxslt/pattern.c libxslt/templates.c libxslt/transform.c: + fixing bugs raised by said tests + Tue Jan 30 18:55:49 CET 2001 Daniel Veillard <Daniel.Veillard@imag.fr> * tests/REC/test-7.*: added more tests diff --git a/libxslt/pattern.c b/libxslt/pattern.c index 50275d1d..8d5556a5 100644 --- a/libxslt/pattern.c +++ b/libxslt/pattern.c @@ -696,6 +696,8 @@ xsltCompileIdKeyPattern(xsltParserContextPtr ctxt, xmlChar *name, int aid) { return; } error: + if (name != NULL) + xmlFree(name); if (lit != NULL) xmlFree(lit); if (lit2 != NULL) @@ -729,6 +731,12 @@ xsltCompileStepPattern(xsltParserContextPtr ctxt, xmlChar *token) { SKIP_BLANKS; if ((token == NULL) && (CUR == '@')) { + NEXT; + if (CUR == '*') { + NEXT; + PUSH(XSLT_OP_ATTR, NULL, NULL); + return; + } token = xsltScanName(ctxt); if (token == NULL) { xsltGenericError(xsltGenericErrorContext, @@ -908,12 +916,14 @@ xsltCompileLocationPathPattern(xsltParserContextPtr ctxt) { } } else if (CUR == '*') { xsltCompileRelativePathPattern(ctxt, NULL); + } else if (CUR == '@') { + xsltCompileRelativePathPattern(ctxt, NULL); } else { xmlChar *name; name = xsltScanName(ctxt); if (name == NULL) { xsltGenericError(xsltGenericErrorContext, - "xsltCompilePattern : Name expected\n"); + "xsltCompileLocationPathPattern : Name expected\n"); ctxt->error = 1; return; } diff --git a/libxslt/templates.c b/libxslt/templates.c index 61d9f4b6..8de3a95d 100644 --- a/libxslt/templates.c +++ b/libxslt/templates.c @@ -266,17 +266,17 @@ xsltAttrTemplateProcess(xsltTransformContextPtr ctxt, xmlNodePtr target, xsltApplyAttributeSet(ctxt, ctxt->node, NULL, in); xmlFree(in); } - return(NULL); - } + return(NULL); } - /* TODO: check for replacement namespaces */ - ret = xmlNewDocProp(ctxt->output, cur->name, NULL); if (ret == NULL) return(NULL); ret->parent = target; - ret->ns = xsltGetNamespace(ctxt, cur->parent, cur->ns, target); + if (cur->ns != NULL) + ret->ns = xsltGetNamespace(ctxt, cur->parent, cur->ns, target); + else + ret->ns = NULL; if (cur->children != NULL) { xmlChar *in = xmlNodeListGetString(ctxt->doc, cur->children, 1); diff --git a/libxslt/transform.c b/libxslt/transform.c index 33c37589..23f30b4c 100644 --- a/libxslt/transform.c +++ b/libxslt/transform.c @@ -125,11 +125,13 @@ xsltCopyNode(xsltTransformContextPtr ctxt, xmlNodePtr node, copy->doc = ctxt->output; if (copy != NULL) { xmlAddChild(insert, copy); - /* - * Add namespaces as they are needed - */ - if (node->nsDef != NULL) - xsltCopyNamespaceList(ctxt, copy, node->nsDef); + if (node->type == XML_ELEMENT_NODE) { + /* + * Add namespaces as they are needed + */ + if (node->nsDef != NULL) + xsltCopyNamespaceList(ctxt, copy, node->nsDef); + } if (node->ns != NULL) { copy->ns = xsltGetNamespace(ctxt, node, node->ns, copy); } @@ -362,21 +364,65 @@ void xsltCopy(xsltTransformContextPtr ctxt, xmlNodePtr node, xmlNodePtr inst) { xmlChar *prop; - xmlNodePtr copy; + xmlNodePtr copy, oldInsert; - if ((node->type != XML_DOCUMENT_NODE) && - (node->type != XML_HTML_DOCUMENT_NODE)) { - copy = xsltCopyNode(ctxt, node, ctxt->insert); - if (node->type == XML_ELEMENT_NODE) { - prop = xmlGetNsProp(inst, (const xmlChar *)"use-attribute-sets", - XSLT_NAMESPACE); - if (prop != NULL) { - TODO /* xsl:copy use-attribute-sets */ + oldInsert = ctxt->insert; + if (ctxt->insert != NULL) { + switch (node->type) { + case XML_DOCUMENT_NODE: + case XML_HTML_DOCUMENT_NODE: + break; + case XML_ELEMENT_NODE: +#ifdef DEBUG_PROCESS + xsltGenericDebug(xsltGenericDebugContext, + "xsl:copy: node %s\n", node->name); +#endif + copy = xsltCopyNode(ctxt, node, ctxt->insert); + ctxt->insert = copy; + prop = xmlGetNsProp(inst, (const xmlChar *)"use-attribute-sets", + XSLT_NAMESPACE); + if (prop != NULL) { + xsltApplyAttributeSet(ctxt, node, inst, prop); + xmlFree(prop); + } + break; + case XML_ATTRIBUTE_NODE: { +#ifdef DEBUG_PROCESS + xsltGenericDebug(xsltGenericDebugContext, + "xsl:copy: attribute %s\n", node->name); +#endif + if (ctxt->insert->type == XML_ELEMENT_NODE) { + xmlAttrPtr attr = (xmlAttrPtr) node, ret, cur; + if (attr->ns != NULL) { + if ((!xmlStrEqual(attr->ns->href, XSLT_NAMESPACE)) && + (xmlStrncasecmp(attr->ns->prefix, + (xmlChar *)"xml", 3))) { + ret = xmlCopyProp(ctxt->insert, attr); + ret->ns = xsltGetNamespace(ctxt, node, attr->ns, + ctxt->insert); + } + } else + ret = xmlCopyProp(ctxt->insert, attr); + + cur = ctxt->insert->properties; + if (cur != NULL) { + while (cur->next != NULL) + cur = cur->next; + cur->next = ret; + ret->prev = cur; + }else + ctxt->insert->properties = ret; + } + break; } + default: + break; + } } xsltApplyOneTemplate(ctxt, ctxt->node, inst->children); + ctxt->insert = oldInsert; } /** @@ -706,6 +752,30 @@ xsltDefaultProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node) { "xsltDefaultProcessOneNode: text copy failed\n"); } return; + case XML_ATTRIBUTE_NODE: + if (ctxt->insert->type == XML_ELEMENT_NODE) { + xmlAttrPtr attr = (xmlAttrPtr) node, ret, cur; + if (attr->ns != NULL) { + if ((!xmlStrEqual(attr->ns->href, XSLT_NAMESPACE)) && + (xmlStrncasecmp(attr->ns->prefix, + (xmlChar *)"xml", 3))) { + ret = xmlCopyProp(ctxt->insert, attr); + ret->ns = xsltGetNamespace(ctxt, node, attr->ns, + ctxt->insert); + } + } else + ret = xmlCopyProp(ctxt->insert, attr); + + cur = ctxt->insert->properties; + if (cur != NULL) { + while (cur->next != NULL) + cur = cur->next; + cur->next = ret; + ret->prev = cur; + }else + ctxt->insert->properties = ret; + } + return; default: return; } @@ -1024,6 +1094,7 @@ error: xmlXPathFreeNodeSet(list); } + /** * xsltApplyOneTemplate: * @ctxt: a XSLT process context @@ -1415,14 +1486,34 @@ xsltProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node) { xsltGenericDebug(xsltGenericDebugContext, "xsltProcessOneNode: no template found for %s\n", node->name); #endif + oldNode = ctxt->node; + ctxt->node = node; xsltDefaultProcessOneNode(ctxt, node); + ctxt->node = oldNode; return; } - oldNode = ctxt->node; - ctxt->node = node; - xsltApplyOneTemplate(ctxt, node, template->content); - ctxt->node = oldNode; + if (node->type == XML_ATTRIBUTE_NODE) { +#ifdef DEBUG_PROCESS + xsltGenericDebug(xsltGenericDebugContext, + "xsltProcessOneNode: applying template for attribute %s\n", + node->name); +#endif + xsltApplyOneTemplate(ctxt, node, template->content); + } else { +#ifdef DEBUG_PROCESS + if (node->type == XML_DOCUMENT_NODE) + xsltGenericDebug(xsltGenericDebugContext, + "xsltProcessOneNode: applying template for /\n"); + else + xsltGenericDebug(xsltGenericDebugContext, + "xsltProcessOneNode: applying template for %s\n", node->name); +#endif + oldNode = ctxt->node; + ctxt->node = node; + xsltApplyOneTemplate(ctxt, node, template->content); + ctxt->node = oldNode; + } } /** diff --git a/tests/REC/test-7.3.out b/tests/REC/test-7.3.out new file mode 100644 index 00000000..923fbfa3 --- /dev/null +++ b/tests/REC/test-7.3.out @@ -0,0 +1,2 @@ +<?xml version="1.0"?> +<doc><?xml-stylesheet href="book.css" type="text/css"?></doc> diff --git a/tests/REC/test-7.3.xml b/tests/REC/test-7.3.xml new file mode 100644 index 00000000..636923c5 --- /dev/null +++ b/tests/REC/test-7.3.xml @@ -0,0 +1,2 @@ +<doc> +</doc> diff --git a/tests/REC/test-7.3.xsl b/tests/REC/test-7.3.xsl new file mode 100644 index 00000000..3f699f11 --- /dev/null +++ b/tests/REC/test-7.3.xsl @@ -0,0 +1,15 @@ +<xsl:stylesheet + version="1.0" + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:fo="http://www.w3.org/1999/XSL/Format" + xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias"> + +<xsl:namespace-alias stylesheet-prefix="axsl" result-prefix="xsl"/> + +<xsl:template match="doc"> +<doc> +<xsl:processing-instruction name="xml-stylesheet">href="book.css" type="text/css"</xsl:processing-instruction> +</doc> +</xsl:template> + +</xsl:stylesheet> diff --git a/tests/REC/test-7.4.out b/tests/REC/test-7.4.out new file mode 100644 index 00000000..cf037f2f --- /dev/null +++ b/tests/REC/test-7.4.out @@ -0,0 +1,2 @@ +<?xml version="1.0"?> +<doc><!--This file is automatically generated. Do not edit!--></doc> diff --git a/tests/REC/test-7.4.xml b/tests/REC/test-7.4.xml new file mode 100644 index 00000000..636923c5 --- /dev/null +++ b/tests/REC/test-7.4.xml @@ -0,0 +1,2 @@ +<doc> +</doc> diff --git a/tests/REC/test-7.4.xsl b/tests/REC/test-7.4.xsl new file mode 100644 index 00000000..80594735 --- /dev/null +++ b/tests/REC/test-7.4.xsl @@ -0,0 +1,15 @@ +<xsl:stylesheet + version="1.0" + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:fo="http://www.w3.org/1999/XSL/Format" + xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias"> + +<xsl:namespace-alias stylesheet-prefix="axsl" result-prefix="xsl"/> + +<xsl:template match="doc"> +<doc> +<xsl:comment>This file is automatically generated. Do not edit!</xsl:comment> +</doc> +</xsl:template> + +</xsl:stylesheet> diff --git a/tests/REC/test-7.5-1.out b/tests/REC/test-7.5-1.out new file mode 100644 index 00000000..450c3f1a --- /dev/null +++ b/tests/REC/test-7.5-1.out @@ -0,0 +1,4 @@ +<?xml version="1.0"?> +<doc attr="value"> + <child attr1="val" attr2="val2">content</child> +</doc> diff --git a/tests/REC/test-7.5-1.xml b/tests/REC/test-7.5-1.xml new file mode 100644 index 00000000..f3a0c0a0 --- /dev/null +++ b/tests/REC/test-7.5-1.xml @@ -0,0 +1,3 @@ +<doc attr="value"> + <child attr1="val" attr2="val2">content</child> +</doc> diff --git a/tests/REC/test-7.5-1.xsl b/tests/REC/test-7.5-1.xsl new file mode 100644 index 00000000..b832f5fa --- /dev/null +++ b/tests/REC/test-7.5-1.xsl @@ -0,0 +1,12 @@ +<xsl:stylesheet + version="1.0" + xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:fo="http://www.w3.org/1999/XSL/Format" + xmlns:axsl="http://www.w3.org/1999/XSL/TransformAlias"> + +<xsl:template match="@*|node()"> + <xsl:copy> + <xsl:apply-templates select="@*|node()"/> + </xsl:copy> +</xsl:template> +</xsl:stylesheet> |