From 9599ea7b74a980a3918eecb44ee9387fefd0beb8 Mon Sep 17 00:00:00 2001 From: Daniel Veillard Date: Wed, 7 Mar 2001 17:05:56 +0000 Subject: [PATCH] I'm gonna change my nick to FlyTox at some point ...: - imports.c transform.c xslt.c xsltInternals.h: fixed a strip-spaces problem - tests/docs/*.xml tests/general/*.[xsl,out]: added reported bugs to testsuite Daniel --- ChangeLog | 7 +++++++ libxslt/imports.c | 8 ++------ libxslt/transform.c | 24 ++++++++++++++++++++++++ libxslt/xslt.c | 14 +++++++++++--- libxslt/xsltInternals.h | 1 + tests/Makefile.am | 3 ++- tests/docs/bug-1-.xml | 7 +++++++ tests/docs/bug-2-.xml | 12 ++++++++++++ tests/docs/character.xml | 23 +++++++++++++++++++++++ tests/general/bug-1-.out | 6 ++++++ tests/general/bug-1-.xsl | 21 +++++++++++++++++++++ tests/general/bug-2-.out | 8 ++++++++ tests/general/bug-2-.xsl | 16 ++++++++++++++++ tests/general/character.out | 2 ++ tests/general/character.xsl | 16 ++++++++++++++++ tests/general/character2.out | 2 ++ tests/general/character2.xsl | 16 ++++++++++++++++ tests/general/itemschoose.out.out | 0 18 files changed, 176 insertions(+), 10 deletions(-) create mode 100644 tests/docs/bug-1-.xml create mode 100644 tests/docs/bug-2-.xml create mode 100644 tests/docs/character.xml create mode 100644 tests/general/bug-1-.out create mode 100644 tests/general/bug-1-.xsl create mode 100644 tests/general/bug-2-.out create mode 100644 tests/general/bug-2-.xsl create mode 100644 tests/general/character.out create mode 100644 tests/general/character.xsl create mode 100644 tests/general/character2.out create mode 100644 tests/general/character2.xsl create mode 100644 tests/general/itemschoose.out.out diff --git a/ChangeLog b/ChangeLog index 68d167e..d61b3b7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Wed Mar 7 18:01:07 CET 2001 Daniel Veillard + + * imports.c transform.c xslt.c xsltInternals.h: fixed a + strip-spaces problem + * tests/docs/*.xml tests/general/*.[xsl,out]: added reported + bugs to testsuite + Wed Mar 7 13:34:13 CET 2001 Daniel Veillard * libxslt/transform.[ch]: finished integrating the current diff --git a/libxslt/imports.c b/libxslt/imports.c index e4e2799..15e80a4 100644 --- a/libxslt/imports.c +++ b/libxslt/imports.c @@ -219,13 +219,9 @@ xsltFindElemSpaceHandling(xsltTransformContextPtr ctxt, xmlNodePtr node) { if (xmlStrEqual(val, (xmlChar *) "preserve")) return(0); } - val = (const xmlChar *) - xmlHashLookup(ctxt->style->stripSpaces, - (const xmlChar *)"*"); - if ((val != NULL) && - (xmlStrEqual(val, (xmlChar *) "strip"))) + if (ctxt->style->stripAll == 1) return(1); - if (xmlStrEqual(val, (xmlChar *) "preserve")) + if (ctxt->style->stripAll == -1) return(0); style = xsltNextImport(style); diff --git a/libxslt/transform.c b/libxslt/transform.c index 001fb69..239860e 100644 --- a/libxslt/transform.c +++ b/libxslt/transform.c @@ -680,6 +680,30 @@ xsltProcessOneNode(xsltTransformContextPtr ctxt, xmlNodePtr node) { xsltTemplatePtr template; xmlNodePtr oldNode; + /* + * Cleanup children empty nodes if asked for + */ + if ((node->children != NULL) && + (xsltFindElemSpaceHandling(ctxt, node))) { + xmlNodePtr delete = NULL, cur = node->children; + + while (cur != NULL) { + if (IS_BLANK_NODE(cur)) + delete = cur; + + cur = cur->next; + if (delete != NULL) { +#ifdef DEBUG_PROCESS + xsltGenericDebug(xsltGenericDebugContext, + "xsltDefaultProcessOneNode: removing ignorable blank node\n"); +#endif + xmlUnlinkNode(delete); + xmlFreeNode(delete); + delete = NULL; + } + } + } + template = xsltGetTemplate(ctxt, node, NULL); /* * If no template is found, apply the default rule. diff --git a/libxslt/xslt.c b/libxslt/xslt.c index 5fd14a9..b30a1fc 100644 --- a/libxslt/xslt.c +++ b/libxslt/xslt.c @@ -622,7 +622,11 @@ xsltParseStylesheetPreserveSpace(xsltStylesheetPtr style, xmlNodePtr cur) { xsltGenericDebug(xsltGenericDebugContext, "add preserved space element %s\n", element); #endif - xmlHashAddEntry(style->stripSpaces, element, "preserve"); + if (xmlStrEqual(element, (const xmlChar *)"*")) { + style->stripAll = -1; + } else { + xmlHashAddEntry(style->stripSpaces, element, "preserve"); + } xmlFree(element); } element = end; @@ -635,7 +639,7 @@ xsltParseStylesheetPreserveSpace(xsltStylesheetPtr style, xmlNodePtr cur) { * @style: the XSLT stylesheet * @template: the "strip-space" prefix * - * parse an XSLT stylesheet strip-space prefix and record + * parse an XSLT stylesheet extension prefix and record * prefixes needing stripping */ @@ -728,7 +732,11 @@ xsltParseStylesheetStripSpace(xsltStylesheetPtr style, xmlNodePtr cur) { xsltGenericDebug(xsltGenericDebugContext, "add stripped space element %s\n", element); #endif - xmlHashAddEntry(style->stripSpaces, element, "strip"); + if (xmlStrEqual(element, (const xmlChar *)"*")) { + style->stripAll = 1; + } else { + xmlHashAddEntry(style->stripSpaces, element, "strip"); + } xmlFree(element); } element = end; diff --git a/libxslt/xsltInternals.h b/libxslt/xsltInternals.h index 48e6c1a..06871b6 100644 --- a/libxslt/xsltInternals.h +++ b/libxslt/xsltInternals.h @@ -120,6 +120,7 @@ struct _xsltStylesheet { xmlDocPtr doc; /* the parsed XML stylesheet */ xmlHashTablePtr stripSpaces;/* the hash table of the strip-space preserve space and cdata-section elements */ + int stripAll; /* strip-space * (1) preserve-space * (-1) */ /* * Global variable or parameters diff --git a/tests/Makefile.am b/tests/Makefile.am index dbcefad..d360190 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -1,6 +1,7 @@ ## Process this file with automake to produce Makefile.in -SUBDIRS=docs REC1 REC2 REC general namespaces numbers documents xmlspec docbook +SUBDIRS=docs REC1 REC2 REC general namespaces numbers documents \ + xmlspec docbook all: diff --git a/tests/docs/bug-1-.xml b/tests/docs/bug-1-.xml new file mode 100644 index 0000000..cc677f7 --- /dev/null +++ b/tests/docs/bug-1-.xml @@ -0,0 +1,7 @@ + + + This is bar 1 + + This is bar 2 + + diff --git a/tests/docs/bug-2-.xml b/tests/docs/bug-2-.xml new file mode 100644 index 0000000..94879b0 --- /dev/null +++ b/tests/docs/bug-2-.xml @@ -0,0 +1,12 @@ + + + + This is bar 1 + + + This is bar 2 + + + This is bar 3 + + diff --git a/tests/docs/character.xml b/tests/docs/character.xml new file mode 100644 index 0000000..815e967 --- /dev/null +++ b/tests/docs/character.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/general/bug-1-.out b/tests/general/bug-1-.out new file mode 100644 index 0000000..bedd070 --- /dev/null +++ b/tests/general/bug-1-.out @@ -0,0 +1,6 @@ + + + This is bar 1 + + This is bar 2 + diff --git a/tests/general/bug-1-.xsl b/tests/general/bug-1-.xsl new file mode 100644 index 0000000..4d7c87d --- /dev/null +++ b/tests/general/bug-1-.xsl @@ -0,0 +1,21 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/general/bug-2-.out b/tests/general/bug-2-.out new file mode 100644 index 0000000..d047b75 --- /dev/null +++ b/tests/general/bug-2-.out @@ -0,0 +1,8 @@ + + + This is bar 1 + + This is bar 2 + + This is bar 3 + diff --git a/tests/general/bug-2-.xsl b/tests/general/bug-2-.xsl new file mode 100644 index 0000000..92f5d92 --- /dev/null +++ b/tests/general/bug-2-.xsl @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + diff --git a/tests/general/character.out b/tests/general/character.out new file mode 100644 index 0000000..2ced81a --- /dev/null +++ b/tests/general/character.out @@ -0,0 +1,2 @@ + +Balance Bluff Climb Diplomacy Escape artist Gather info Hide Jump Listen Move silently Perform Ride Search Sense motive Spot Swim Tumble Use rope diff --git a/tests/general/character.xsl b/tests/general/character.xsl new file mode 100644 index 0000000..34eaa73 --- /dev/null +++ b/tests/general/character.xsl @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + diff --git a/tests/general/character2.out b/tests/general/character2.out new file mode 100644 index 0000000..2ced81a --- /dev/null +++ b/tests/general/character2.out @@ -0,0 +1,2 @@ + +Balance Bluff Climb Diplomacy Escape artist Gather info Hide Jump Listen Move silently Perform Ride Search Sense motive Spot Swim Tumble Use rope diff --git a/tests/general/character2.xsl b/tests/general/character2.xsl new file mode 100644 index 0000000..c3ff26e --- /dev/null +++ b/tests/general/character2.xsl @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + diff --git a/tests/general/itemschoose.out.out b/tests/general/itemschoose.out.out new file mode 100644 index 0000000..e69de29 -- 2.7.4