Re: [xslt] xsl:strip-space bug



  Hi Robert,

[...]
> The output is:
> -snip-
> <?xml version="1.0"?>
> <FOO>
>   <BAR INDEX="2">
>     This is bar 1
>   </BAR>
>   <BAR INDEX="4">
>     This is bar 2
>   </BAR>
>   <BAR INDEX="6">
>     This is bar 3
>   </BAR>
> </FOO>
> -snip-
> 
> Now, I expected the INDEX values to be 1, 2, 3, respectively. When I
> replace '*' with 'foo' in <xsl:strip-space>, it indeed shows 1, 2, 3.
> 
> Either I'm missing something, or libxslt is :)

  Sure, it's a bug ... I just fixed it in CVS, I also included the fix
(but can't guarantee it will apply cleanly on 0.4.0,

Daniel

-- 
Daniel Veillard      | Red Hat Network http://redhat.com/products/network/
veillard redhat com  | libxml Gnome XML toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
Index: imports.c
===================================================================
RCS file: /cvs/gnome/libxslt/libxslt/imports.c,v
retrieving revision 1.3
diff -c -r1.3 imports.c
*** imports.c	2001/02/11 20:12:22	1.3
--- imports.c	2001/03/07 16:57:03
***************
*** 219,231 ****
  	    if (xmlStrEqual(val, (xmlChar *) "preserve"))
  		return(0);
  	} 
! 	val = (const xmlChar *)
! 	      xmlHashLookup(ctxt->style->stripSpaces,
! 			    (const xmlChar *)"*");
! 	if ((val != NULL) &&
! 	    (xmlStrEqual(val, (xmlChar *) "strip")))
  	    return(1);
! 	if (xmlStrEqual(val, (xmlChar *) "preserve"))
  	    return(0);
  
  	style = xsltNextImport(style);
--- 219,227 ----
  	    if (xmlStrEqual(val, (xmlChar *) "preserve"))
  		return(0);
  	} 
! 	if (ctxt->style->stripAll == 1)
  	    return(1);
! 	if (ctxt->style->stripAll == -1)
  	    return(0);
  
  	style = xsltNextImport(style);
Index: transform.c
===================================================================
RCS file: /cvs/gnome/libxslt/libxslt/transform.c,v
retrieving revision 1.63
diff -c -r1.63 transform.c
*** transform.c	2001/03/07 12:36:39	1.63
--- transform.c	2001/03/07 16:57:03
***************
*** 680,685 ****
--- 680,709 ----
      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.
Index: xslt.c
===================================================================
RCS file: /cvs/gnome/libxslt/libxslt/xslt.c,v
retrieving revision 1.35
diff -c -r1.35 xslt.c
*** xslt.c	2001/02/27 13:18:39	1.35
--- xslt.c	2001/03/07 16:57:04
***************
*** 622,628 ****
  	    xsltGenericDebug(xsltGenericDebugContext,
  		"add preserved space element %s\n", element);
  #endif
! 	    xmlHashAddEntry(style->stripSpaces, element, "preserve");
  	    xmlFree(element);
  	}
  	element = end;
--- 622,632 ----
  	    xsltGenericDebug(xsltGenericDebugContext,
  		"add preserved space element %s\n", element);
  #endif
! 	    if (xmlStrEqual(element, (const xmlChar *)"*")) {
! 		style->stripAll = -1;
! 	    } else {
! 		xmlHashAddEntry(style->stripSpaces, element, "preserve");
! 	    }
  	    xmlFree(element);
  	}
  	element = end;
***************
*** 635,641 ****
   * @style:  the XSLT stylesheet
   * @template:  the "strip-space" prefix
   *
!  * parse an XSLT stylesheet strip-space prefix and record
   * prefixes needing stripping
   */
  
--- 639,645 ----
   * @style:  the XSLT stylesheet
   * @template:  the "strip-space" prefix
   *
!  * parse an XSLT stylesheet extension prefix and record
   * prefixes needing stripping
   */
  
***************
*** 728,734 ****
  	    xsltGenericDebug(xsltGenericDebugContext,
  		"add stripped space element %s\n", element);
  #endif
! 	    xmlHashAddEntry(style->stripSpaces, element, "strip");
  	    xmlFree(element);
  	}
  	element = end;
--- 732,742 ----
  	    xsltGenericDebug(xsltGenericDebugContext,
  		"add stripped space element %s\n", element);
  #endif
! 	    if (xmlStrEqual(element, (const xmlChar *)"*")) {
! 		style->stripAll = 1;
! 	    } else {
! 		xmlHashAddEntry(style->stripSpaces, element, "strip");
! 	    }
  	    xmlFree(element);
  	}
  	element = end;
Index: xsltInternals.h
===================================================================
RCS file: /cvs/gnome/libxslt/libxslt/xsltInternals.h,v
retrieving revision 1.32
diff -c -r1.32 xsltInternals.h
*** xsltInternals.h	2001/03/06 18:41:20	1.32
--- xsltInternals.h	2001/03/07 16:57:04
***************
*** 120,125 ****
--- 120,126 ----
      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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]