Re: [xslt] Release candidate 1 of libxslt-1.1.27



On Fri, Sep 07, 2012 at 09:59:26AM -0400, Phil Shafer wrote:
> Daniel Veillard writes:
> >  Just wondering, shouldn't that attribute be namespaced ? 
> 
> Extension attributes are typically namespaced.  For example
> the <func:function name="xxx"> or <func:result select="yyyy">.
> The "select" attribute for <redirect:write> also has no
> namespace.
> 
> >Where is this described ?
> 
> http://xml.apache.org/xalan-j/apidocs/org/apache/xalan/lib/Redirect.html
> 
>     Calls to redirect:write and redirect:open also take an optional
>     attribute append="true|yes", which will attempt to simply append
>     to an existing file instead of always opening a new file. The
>     default behavior of always overwriting the file still happens
>     if you do not specify append.

  Okay, when you say redirect:write, you actually mean EXSLT:document
as per:
  http://www.exslt.org/exsl/elements/document/index.html

so what your patch tries to do is add an append="true|yes" optional
attribute which will open the file in append mode instead of overwrite
if it already exists.

  To be honnest your original patch is pure crack except for the
beginning which I retained, I removed the leak and API change and
instead used the existing APIs in place for what you need.

  Try it if you validate I will push this as this looks relatively
safe even if it extends ESXLT document in ways not expected by the
description,

Daniel

diff --git a/libxslt/transform.c b/libxslt/transform.c
index 4c6b2a5..3770c3d 100644
--- a/libxslt/transform.c
+++ b/libxslt/transform.c
@@ -20,6 +20,7 @@
 #include "libxslt.h"
 
 #include <string.h>
+#include <stdio.h>
 
 #include <libxml/xmlmemory.h>
 #include <libxml/parser.h>
@@ -3293,6 +3294,7 @@ xsltDocumentElem(xsltTransformContextPtr ctxt, xmlNodePtr node,
     const xmlChar *doctypeSystem;
     const xmlChar *version;
     const xmlChar *encoding;
+    int redirect_write_append = 0;
 
     if ((ctxt == NULL) || (node == NULL) || (inst == NULL) || (comp == NULL))
         return;
@@ -3708,10 +3710,38 @@ xsltDocumentElem(xsltTransformContextPtr ctxt, xmlNodePtr node,
     }
 
     /*
-     * Save the result
+     * Calls to redirect:write also take an optional attribute append.
+     * Attribute append="true|yes" which will attempt to simply append
+     * to an existing file instead of always opening a new file. The
+     * default behavior of always overwriting the file still happens
+     * if we do not specify append.
+     * Note that append use will forbid use of remote URI target.
      */
-    ret = xsltSaveResultToFilename((const char *) filename,
-                                   res, style, 0);
+    prop = xsltEvalAttrValueTemplate(ctxt, inst, (const xmlChar *)"append",
+				     NULL);
+    if (prop != NULL) {
+	if (xmlStrEqual(prop, (const xmlChar *) "true") ||
+	    xmlStrEqual(prop, (const xmlChar *) "yes")) {
+	    style->omitXmlDeclaration = 1;
+	    redirect_write_append = 1;
+	} else
+	    style->omitXmlDeclaration = 0;
+	xmlFree(prop);
+    }
+
+    if (redirect_write_append) {
+        FILE *f;
+
+	f = fopen((const char *) filename, "ab");
+	if (f == NULL) {
+	    ret = -1;
+	} else {
+	    ret = xsltSaveResultToFile(f, res, style);
+	    fclose(f);
+	}
+    } else {
+	ret = xsltSaveResultToFilename((const char *) filename, res, style, 0);
+    }
     if (ret < 0) {
 	xsltTransformError(ctxt, NULL, inst,
                          "xsltDocumentElem: unable to save to %s\n",

-- 
Daniel Veillard      | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
daniel veillard com  | Rpmfind RPM search engine http://rpmfind.net/
http://veillard.com/ | virtualization library  http://libvirt.org/


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