From f2914bee43533e6bcea40066ad50a90267ea3456 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Wed, 21 Aug 2002 11:50:53 +0000 Subject: [PATCH] fixed bug #89258 and a bit of cleanup. added the example in the regression * libxslt/transform.c libxslt/xslt.c: fixed bug #89258 and a bit of cleanup. * tests/docs/Makefile.am tests/docs/bug-90.xml tests/general/Makefile.am tests/general/bug-90.*: added the example in the regression tests for this case Daniel --- ChangeLog | 8 ++++++++ libxslt/transform.c | 38 +++++++++++++++++++++++++------------- libxslt/xslt.c | 25 +++++++++++++------------ tests/docs/Makefile.am | 1 + tests/docs/bug-90.xml | 15 +++++++++++++++ tests/general/Makefile.am | 1 + tests/general/bug-90.out | 17 +++++++++++++++++ tests/general/bug-90.xsl | 35 +++++++++++++++++++++++++++++++++++ 8 files changed, 115 insertions(+), 25 deletions(-) create mode 100644 tests/docs/bug-90.xml create mode 100644 tests/general/bug-90.out create mode 100644 tests/general/bug-90.xsl diff --git a/ChangeLog b/ChangeLog index 7c904f87..84a116f9 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Wed Aug 21 13:48:07 CEST 2002 Daniel Veillard + + * libxslt/transform.c libxslt/xslt.c: fixed bug #89258 and a bit of + cleanup. + * tests/docs/Makefile.am tests/docs/bug-90.xml + tests/general/Makefile.am tests/general/bug-90.*: added the + example in the regression tests for this case + Tue Aug 20 16:40:48 CEST 2002 Igor Zlatkovic * win32/Makefile.msvc: added the prefix location to the include diff --git a/libxslt/transform.c b/libxslt/transform.c index 52dd28a7..38c67a5f 100644 --- a/libxslt/transform.c +++ b/libxslt/transform.c @@ -344,6 +344,7 @@ xmlNodePtr xsltCopyTree(xsltTransformContextPtr ctxt, xmlNodePtr node, * @ctxt: a XSLT process context * @target: the element where the text will be attached * @string: the text string + * @noescape: should disable-escaping be activated for this text node. * * Create a text node * @@ -351,7 +352,7 @@ xmlNodePtr xsltCopyTree(xsltTransformContextPtr ctxt, xmlNodePtr node, */ static xmlNodePtr xsltCopyTextString(xsltTransformContextPtr ctxt, xmlNodePtr target, - const xmlChar *string) { + const xmlChar *string, int noescape) { xmlNodePtr copy; if (string == NULL) @@ -363,14 +364,28 @@ xsltCopyTextString(xsltTransformContextPtr ctxt, xmlNodePtr target, string); #endif - /* TODO: handle coalescing of text nodes here */ + /* handle coalescing of text nodes here */ if ((ctxt->type == XSLT_OUTPUT_XML) && (ctxt->style->cdataSection != NULL) && (target != NULL) && (xmlHashLookup(ctxt->style->cdataSection, target->name) != NULL)) { + if ((target != NULL) && (target->last != NULL) && + (target->last->type == XML_CDATA_SECTION_NODE)) { + xmlNodeAddContent(target->last, string); + return(target->last); + } copy = xmlNewCDataBlock(ctxt->output, string, xmlStrlen(string)); + } else if ((noescape) && (ctxt->type == XSLT_OUTPUT_XML)) { + if ((target != NULL) && (target->last != NULL) && + (target->last->type == XML_TEXT_NODE) && + (target->last->name == xmlStringTextNoenc)) { + xmlNodeAddContent(target->last, string); + return(target->last); + } + copy = xmlNewText(string); + copy->name = xmlStringTextNoenc; } else { if ((target != NULL) && (target->last != NULL) && (target->last->type == XML_TEXT_NODE) && @@ -2450,7 +2465,7 @@ xsltCopyOf(xsltTransformContextPtr ctxt, xmlNodePtr node, "xsltCopyOf: result %s\n", res->stringval); #endif /* append content as text node */ - xsltCopyTextString(ctxt, ctxt->insert, res->stringval); + xsltCopyTextString(ctxt, ctxt->insert, res->stringval, 0); } } } else { @@ -2509,21 +2524,18 @@ xsltValueOf(xsltTransformContextPtr ctxt, xmlNodePtr node, if (res->type != XPATH_STRING) res = xmlXPathConvertString(res); if (res->type == XPATH_STRING) { - /* TODO: integrate with xsltCopyTextString */ - copy = xmlNewText(res->stringval); - if (copy != NULL) { - if (comp->noescape) - copy->name = xmlStringTextNoenc; - xmlAddChild(ctxt->insert, copy); - } + copy = xsltCopyTextString(ctxt, ctxt->insert, res->stringval, + comp->noescape); } } else { ctxt->state = XSLT_STATE_STOPPED; } if (copy == NULL) { - xsltPrintErrorContext(ctxt, NULL, inst); - xsltGenericError(xsltGenericErrorContext, - "xsltValueOf: text copy failed\n"); + if ((res == NULL) || (res->stringval != NULL)) { + xsltPrintErrorContext(ctxt, NULL, inst); + xsltGenericError(xsltGenericErrorContext, + "xsltValueOf: text copy failed\n"); + } } #ifdef WITH_XSLT_DEBUG_PROCESS else diff --git a/libxslt/xslt.c b/libxslt/xslt.c index e85a88f3..f7b93d04 100644 --- a/libxslt/xslt.c +++ b/libxslt/xslt.c @@ -1752,18 +1752,19 @@ xsltParseStylesheetTop(xsltStylesheetPtr style, xmlNodePtr top) { /* * process xsl:import elements */ - 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; - } + 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; + } + /* * process other top-level elements */ diff --git a/tests/docs/Makefile.am b/tests/docs/Makefile.am index 8e02a1e3..232aaaf6 100644 --- a/tests/docs/Makefile.am +++ b/tests/docs/Makefile.am @@ -89,6 +89,7 @@ EXTRA_DIST = \ bug-87.xml \ bug-88.xml \ bug-89.xml \ + bug-90.xml \ character.xml \ array.xml \ items.xml diff --git a/tests/docs/bug-90.xml b/tests/docs/bug-90.xml new file mode 100644 index 00000000..99894746 --- /dev/null +++ b/tests/docs/bug-90.xml @@ -0,0 +1,15 @@ + + + + + + + + + http://www.pears.com/index.html + + diff --git a/tests/general/Makefile.am b/tests/general/Makefile.am index a774f42e..1701b225 100644 --- a/tests/general/Makefile.am +++ b/tests/general/Makefile.am @@ -92,6 +92,7 @@ EXTRA_DIST = \ bug-87.out bug-87.xsl \ bug-88.out bug-88.xsl \ bug-89.out bug-89.xsl \ + bug-90.out bug-90.xsl \ character.out character.xsl \ character2.out character2.xsl \ itemschoose.out itemschoose.xsl \ diff --git a/tests/general/bug-90.out b/tests/general/bug-90.out new file mode 100644 index 00000000..04765ecb --- /dev/null +++ b/tests/general/bug-90.out @@ -0,0 +1,17 @@ + + + + + + + + + diff --git a/tests/general/bug-90.xsl b/tests/general/bug-90.xsl new file mode 100644 index 00000000..a9eb9a87 --- /dev/null +++ b/tests/general/bug-90.xsl @@ -0,0 +1,35 @@ + + + + + + + The site is at + + + + + + The site is at + + + + + + + + + <![CDATA[ ]]> + +