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



Daniel Veillard writes:
>  I tagged the git and pushed a tarball of the rc1 to:
>   ftp://xmlsoft.org/libxslt/

Please consider this patch that adds append functionality to
the <redirect:write> element via the "append" attribute.
This attribute is already supported in Xalan and SAXON.

Thanks,
 Phil


----------------

Index: branches/IB4_10_5_BRANCH/gpl-dist/libxslt/libxslt/transform.c
===================================================================
--- branches/IB4_10_5_BRANCH/gpl-dist/libxslt/libxslt/transform.c	(revision 384559)
+++ branches/IB4_10_5_BRANCH/gpl-dist/libxslt/libxslt/transform.c	(revision 384560)
@@ -3216,6 +3215,7 @@ xsltDocumentElem(xsltTransformContextPtr ctxt, xml
     const xmlChar *doctypePublic;
     const xmlChar *doctypeSystem;
     const xmlChar *version;
+    int redirect_write_append = 0;
 
     if ((ctxt == NULL) || (node == NULL) || (inst == NULL) || (comp == NULL))
         return;
@@ -3630,10 +3630,25 @@ xsltDocumentElem(xsltTransformContextPtr ctxt, xml
     }
 
     /*
-     * 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 donot specify append.
      */
+    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;
+    }
+
     ret = xsltSaveResultToFilename((const char *) filename,
-                                   res, style, 0);
+                                   res, style, 0, redirect_write_append);
     if (ret < 0) {
 	xsltTransformError(ctxt, NULL, inst,
                          "xsltDocumentElem: unable to save to %s\n",
@@ -6339,7 +6354,7 @@ xsltRunStylesheetUser(xsltStylesheetPtr style, xml
         /* TODO: incomplete, IObuf output not progressive */
         ret = xsltSaveResultTo(IObuf, tmp, style);
     } else {
-        ret = xsltSaveResultToFilename(output, tmp, style, 0);
+        ret = xsltSaveResultToFilename(output, tmp, style, 0, 0);
     }
     xmlFreeDoc(tmp);
     return (ret);
Index: branches/IB4_10_5_BRANCH/gpl-dist/libxslt/libxslt/xsltutils.c
===================================================================
--- branches/IB4_10_5_BRANCH/gpl-dist/libxslt/libxslt/xsltutils.c	(revision 384559)
+++ branches/IB4_10_5_BRANCH/gpl-dist/libxslt/libxslt/xsltutils.c	(revision 384560)
@@ -1582,7 +1582,7 @@ xsltSaveResultTo(xmlOutputBufferPtr buf, xmlDocPtr
  */
 int
 xsltSaveResultToFilename(const char *URL, xmlDocPtr result,
-			 xsltStylesheetPtr style, int compression) {
+			 xsltStylesheetPtr style, int compression, int mode) {
     xmlOutputBufferPtr buf;
     const xmlChar *encoding;
     int ret;
@@ -1601,9 +1601,9 @@ xsltSaveResultToFilename(const char *URL, xmlDocPt
 	    (xmlStrEqual((const xmlChar *)encoder->name,
 			 (const xmlChar *) "UTF-8")))
 	    encoder = NULL;
-	buf = xmlOutputBufferCreateFilename(URL, encoder, compression);
+	buf = xmlOutputBufferCreateFilename(URL, encoder, compression, mode);
     } else {
-	buf = xmlOutputBufferCreateFilename(URL, NULL, compression);
+	buf = xmlOutputBufferCreateFilename(URL, NULL, compression, mode);
     }
     if (buf == NULL)
 	return(-1);
Index: branches/IB4_10_5_BRANCH/gpl-dist/libxslt/libxslt/xsltutils.h
===================================================================
--- branches/IB4_10_5_BRANCH/gpl-dist/libxslt/libxslt/xsltutils.h	(revision 384559)
+++ branches/IB4_10_5_BRANCH/gpl-dist/libxslt/libxslt/xsltutils.h	(revision 384560)
@@ -221,7 +221,8 @@ XSLTPUBFUN int XSLTCALL
     		xsltSaveResultToFilename	(const char *URI,
 						 xmlDocPtr result,
 						 xsltStylesheetPtr style,
-						 int compression);
+						 int compression,
+						 int mode);
 XSLTPUBFUN int XSLTCALL		
     		xsltSaveResultToFile		(FILE *file,
 						 xmlDocPtr result,
Index: branches/IB4_10_5_BRANCH/dist/php/ext/dom/node.c
===================================================================
--- branches/IB4_10_5_BRANCH/dist/php/ext/dom/node.c	(revision 384559)
+++ branches/IB4_10_5_BRANCH/dist/php/ext/dom/node.c	(revision 384560)
@@ -1807,7 +1807,7 @@ static void dom_canonicalization(INTERNAL_FUNCTION
 	}
 
 	if (mode == 1) {
-		buf = xmlOutputBufferCreateFilename(file, NULL, 0);
+		buf = xmlOutputBufferCreateFilename(file, NULL, 0, 0);
 	} else {
 		buf = xmlAllocOutputBuffer(NULL);
 	}
Index: branches/IB4_10_5_BRANCH/dist/php/ext/xsl/xsltprocessor.c
===================================================================
--- branches/IB4_10_5_BRANCH/dist/php/ext/xsl/xsltprocessor.c	(revision 384559)
+++ branches/IB4_10_5_BRANCH/dist/php/ext/xsl/xsltprocessor.c	(revision 384560)
@@ -551,7 +551,7 @@ PHP_FUNCTION(xsl_xsltprocessor_transform_to_uri)
 
 	ret = -1;
 	if (newdocp) {
-		ret = xsltSaveResultToFilename(uri, newdocp, sheetp, 0);
+		ret = xsltSaveResultToFilename(uri, newdocp, sheetp, 0, 0);
 		xmlFreeDoc(newdocp);
 	}
 
Index: branches/IB4_10_5_BRANCH/dist/php/ext/simplexml/simplexml.c
===================================================================
--- branches/IB4_10_5_BRANCH/dist/php/ext/simplexml/simplexml.c	(revision 384559)
+++ branches/IB4_10_5_BRANCH/dist/php/ext/simplexml/simplexml.c	(revision 384560)
@@ -1247,7 +1247,7 @@ SXE_METHOD(asXML)
 					RETURN_TRUE;
 				}
 			} else {
-				outbuf = xmlOutputBufferCreateFilename(filename, NULL, 0);
+				outbuf = xmlOutputBufferCreateFilename(filename, NULL, 0, 0);
 
 				if (outbuf == NULL) {
 					RETURN_FALSE;
Index: branches/IB4_10_5_BRANCH/dist/libxml2/include/libxml/xmlIO.h
===================================================================
--- branches/IB4_10_5_BRANCH/dist/libxml2/include/libxml/xmlIO.h	(revision 384559)
+++ branches/IB4_10_5_BRANCH/dist/libxml2/include/libxml/xmlIO.h	(revision 384560)
@@ -86,7 +86,7 @@ typedef int (XMLCALL *xmlOutputMatchCallback) (cha
  *
  * Returns an Output context or NULL in case or error
  */
-typedef void * (XMLCALL *xmlOutputOpenCallback) (char const *filename);
+typedef void * (XMLCALL *xmlOutputOpenCallback) (char const *filename, int mode);
 /**
  * xmlOutputWriteCallback:
  * @context:  an Output context
@@ -225,7 +225,7 @@ XMLPUBFUN xmlOutputBufferPtr XMLCALL
 XMLPUBFUN xmlOutputBufferPtr XMLCALL
 	xmlOutputBufferCreateFilename	(const char *URI,
 					 xmlCharEncodingHandlerPtr encoder,
-					 int compression);
+					 int compression, int mode);
 
 XMLPUBFUN xmlOutputBufferPtr XMLCALL
 	xmlOutputBufferCreateFile	(FILE *file,
@@ -271,7 +271,7 @@ XMLPUBFUN int XMLCALL
 xmlOutputBufferPtr
 	__xmlOutputBufferCreateFilename(const char *URI,
                               xmlCharEncodingHandlerPtr encoder,
-                              int compression);
+                              int compression, int mode);
 
 #ifdef LIBXML_HTTP_ENABLED
 /*  This function only exists if HTTP support built into the library  */
Index: branches/IB4_10_5_BRANCH/dist/libxml2/testapi.c
===================================================================
--- branches/IB4_10_5_BRANCH/dist/libxml2/testapi.c	(revision 384559)
+++ branches/IB4_10_5_BRANCH/dist/libxml2/testapi.c	(revision 384560)
@@ -652,7 +652,7 @@ static void des_xmlXPathObjectPtr(int no ATTRIBUTE
 #ifdef LIBXML_OUTPUT_ENABLED
 #define gen_nb_xmlOutputBufferPtr 2
 static xmlOutputBufferPtr gen_xmlOutputBufferPtr(int no, int nr ATTRIBUTE_UNUSED) {
-    if (no == 0) return(xmlOutputBufferCreateFilename("test.out", NULL, 0));
+    if (no == 0) return(xmlOutputBufferCreateFilename("test.out", NULL, 0, 0));
     return(NULL);
 }
 static void des_xmlOutputBufferPtr(int no ATTRIBUTE_UNUSED, xmlOutputBufferPtr val, int nr ATTRIBUTE_UNUSED) {
@@ -28038,7 +28038,7 @@ test_xmlOutputBufferCreateFilename(void) {
         encoder = gen_xmlCharEncodingHandlerPtr(n_encoder, 1);
         compression = gen_int(n_compression, 2);
 
-        ret_val = xmlOutputBufferCreateFilename(URI, encoder, compression);
+        ret_val = xmlOutputBufferCreateFilename(URI, encoder, compression, 0);
         desret_xmlOutputBufferPtr(ret_val);
         call_tests++;
         des_fileoutput(n_URI, URI, 0);
Index: branches/IB4_10_5_BRANCH/dist/libxml2/HTMLtree.c
===================================================================
--- branches/IB4_10_5_BRANCH/dist/libxml2/HTMLtree.c	(revision 384559)
+++ branches/IB4_10_5_BRANCH/dist/libxml2/HTMLtree.c	(revision 384560)
@@ -1121,7 +1121,7 @@ htmlSaveFile(const char *filename, xmlDocPtr cur)
     /* 
      * save the content to a temp buffer.
      */
-    buf = xmlOutputBufferCreateFilename(filename, handler, cur->compression);
+    buf = xmlOutputBufferCreateFilename(filename, handler, cur->compression, 0);
     if (buf == NULL) return(0);
 
     htmlDocContentDumpOutput(buf, cur, NULL);
@@ -1185,7 +1185,7 @@ htmlSaveFileFormat(const char *filename, xmlDocPtr
     /* 
      * save the content to a temp buffer.
      */
-    buf = xmlOutputBufferCreateFilename(filename, handler, 0);
+    buf = xmlOutputBufferCreateFilename(filename, handler, 0, 0);
     if (buf == NULL) return(0);
 
     htmlDocContentDumpFormatOutput(buf, cur, encoding, format);
Index: branches/IB4_10_5_BRANCH/dist/libxml2/xmlIO.c
===================================================================
--- branches/IB4_10_5_BRANCH/dist/libxml2/xmlIO.c	(revision 384559)
+++ branches/IB4_10_5_BRANCH/dist/libxml2/xmlIO.c	(revision 384560)
@@ -910,6 +910,7 @@ xmlFileOpen (const char *filename) {
 /**
  * xmlFileOpenW:
  * @filename:  the URI for matching
+ * @mode:  type of access (0 - write, 1 - append)
  *
  * output to from FILE *,
  * if @filename is "-" then the standard output is used
@@ -917,7 +918,7 @@ xmlFileOpen (const char *filename) {
  * Returns an I/O context or NULL in case of error
  */
 static void *
-xmlFileOpenW (const char *filename) {
+xmlFileOpenW (const char *filename, int mode) {
     const char *path = NULL;
     FILE *fd;
 
@@ -947,7 +948,7 @@ static void *
 #if defined(_WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
     fd = xmlWrapOpen(path, 1);
 #else
-  	   fd = fopen(path, "wb");
+    fd = fopen(path, mode ? "a+" : "wb");
 #endif /* WIN32 */
 
 	 if (fd == NULL) xmlIOErr(0, path);
@@ -2450,7 +2451,7 @@ xmlParserInputBufferCreateFilename(const char *URI
 xmlOutputBufferPtr
 __xmlOutputBufferCreateFilename(const char *URI,
                               xmlCharEncodingHandlerPtr encoder,
-                              int compression ATTRIBUTE_UNUSED) {
+                              int compression ATTRIBUTE_UNUSED, int mode) {
     xmlOutputBufferPtr ret;
     xmlURIPtr puri;
     int i = 0;
@@ -2511,7 +2512,7 @@ __xmlOutputBufferCreateFilename(const char *URI,
 		    context = xmlIOHTTPOpenW(unescaped, compression);
 		else
 #endif
-		    context = xmlOutputCallbackTable[i].opencallback(unescaped);
+		    context = xmlOutputCallbackTable[i].opencallback(unescaped, mode);
 		if (context != NULL)
 		    break;
 	    }
@@ -2547,7 +2548,7 @@ __xmlOutputBufferCreateFilename(const char *URI,
 		    context = xmlIOHTTPOpenW(URI, compression);
 		else
 #endif
-		    context = xmlOutputCallbackTable[i].opencallback(URI);
+		    context = xmlOutputCallbackTable[i].opencallback(URI, mode);
 		if (context != NULL)
 		    break;
 	    }
@@ -2588,11 +2589,11 @@ __xmlOutputBufferCreateFilename(const char *URI,
 xmlOutputBufferPtr
 xmlOutputBufferCreateFilename(const char *URI,
                               xmlCharEncodingHandlerPtr encoder,
-                              int compression ATTRIBUTE_UNUSED) {
+                              int compression ATTRIBUTE_UNUSED, int mode) {
     if ((xmlOutputBufferCreateFilenameValue)) {
 		return xmlOutputBufferCreateFilenameValue(URI, encoder, compression);
 	}
-	return __xmlOutputBufferCreateFilename(URI, encoder, compression);
+	return __xmlOutputBufferCreateFilename(URI, encoder, compression, mode);
 }
 #endif /* LIBXML_OUTPUT_ENABLED */
 
Index: branches/IB4_10_5_BRANCH/dist/libxml2/xmlwriter.c
===================================================================
--- branches/IB4_10_5_BRANCH/dist/libxml2/xmlwriter.c	(revision 384559)
+++ branches/IB4_10_5_BRANCH/dist/libxml2/xmlwriter.c	(revision 384560)
@@ -240,7 +240,7 @@ xmlNewTextWriterFilename(const char *uri, int comp
     xmlTextWriterPtr ret;
     xmlOutputBufferPtr out;
 
-    out = xmlOutputBufferCreateFilename(uri, NULL, compression);
+    out = xmlOutputBufferCreateFilename(uri, NULL, compression, 0);
     if (out == NULL) {
         xmlWriterErrMsg(NULL, XML_ERR_NO_MEMORY,
                         "xmlNewTextWriterFilename : out of memory!\n");
Index: branches/IB4_10_5_BRANCH/dist/libxml2/xmlsave.c
===================================================================
--- branches/IB4_10_5_BRANCH/dist/libxml2/xmlsave.c	(revision 384559)
+++ branches/IB4_10_5_BRANCH/dist/libxml2/xmlsave.c	(revision 384560)
@@ -1536,7 +1536,7 @@ xmlSaveToFilename(const char *filename, const char
     ret = xmlNewSaveCtxt(encoding, options);
     if (ret == NULL) return(NULL);
     ret->buf = xmlOutputBufferCreateFilename(filename, ret->handler,
-                                             compression);
+                                             compression, 0);
     if (ret->buf == NULL) {
 	xmlFreeSaveCtxt(ret);
 	return(NULL);
@@ -2342,7 +2342,7 @@ xmlSaveFormatFileEnc( const char * filename, xmlDo
     /* 
      * save the content to a temp buffer.
      */
-    buf = xmlOutputBufferCreateFilename(filename, handler, cur->compression);
+    buf = xmlOutputBufferCreateFilename(filename, handler, cur->compression, 0);
     if (buf == NULL) return(-1);
     memset(&ctxt, 0, sizeof(ctxt));
     ctxt.doc = cur;
Index: branches/IB4_10_5_BRANCH/dist/libxml2/c14n.c
===================================================================
--- branches/IB4_10_5_BRANCH/dist/libxml2/c14n.c	(revision 384559)
+++ branches/IB4_10_5_BRANCH/dist/libxml2/c14n.c	(revision 384560)
@@ -1782,7 +1782,7 @@ xmlC14NDocSave(xmlDocPtr doc, xmlNodeSetPtr nodes,
     /* 
      * save the content to a temp buffer, use default UTF8 encoding.
      */
-    buf = xmlOutputBufferCreateFilename(filename, NULL, compression);
+    buf = xmlOutputBufferCreateFilename(filename, NULL, compression, 0);
     if (buf == NULL) {
         xmlC14NErrInternal("creating temporary filename");
         return (-1);


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