xsltparser.c

Go to the documentation of this file.
00001 /* xsltparser.c  --  Generic XSLT parser for eurephiadm
00002  *
00003  *  GPLv2 only - Copyright (C) 2009 - 2010
00004  *               David Sommerseth <dazo@users.sourceforge.net>
00005  *
00006  *  This program is free software; you can redistribute it and/or
00007  *  modify it under the terms of the GNU General Public License
00008  *  as published by the Free Software Foundation; version 2
00009  *  of the License.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
00019  *
00020  */
00021 
00031 #include <stdio.h>
00032 
00033 #ifdef HAVE_LIBXML2
00034 #include <libxml/tree.h>
00035 #include <libxml/xmlstring.h>
00036 #endif
00037 
00038 #ifdef HAVE_LIBXSLT
00039 #include <libxslt/xsltInternals.h>
00040 #include <libxslt/transform.h>
00041 #include <libxslt/xsltutils.h>
00042 #endif
00043 
00044 #include <eurephia_values.h>
00045 
00046 
00059 int xslt_print_xmldoc(FILE *dst, eurephiaVALUES *cfg, xmlDoc *xmldoc,
00060                       const char *xsltfname, const char **xsltparams)
00061 {
00062 #ifdef HAVE_LIBXSLT
00063         xmlDoc *result = NULL;
00064         xsltStylesheet *xslt = NULL;
00065         xmlChar xsltfile[2048];
00066 
00067         // Build up complete path to the XSLT template we will use
00068         xmlStrPrintf(xsltfile,2046, (xmlChar *)"%s/%s%c", eGet_value(cfg, "eurephiadm_xslt_path"), xsltfname, 0);
00069 
00070         // Load the XSLT template
00071         xslt = xsltParseStylesheetFile(xsltfile);
00072         if( xslt == NULL ) {
00073                 return 0;
00074         }
00075 
00076         // Parse the XML document, using the XSLT template
00077         result = xsltApplyStylesheet(xslt, xmldoc, xsltparams);
00078         if( result == NULL ) {
00079                 return 0;
00080         }
00081 
00082         // Send the result to file
00083         xsltSaveResultToFile(dst, result, xslt);
00084 
00085         // Clean up
00086         xmlFreeDoc(result);
00087         xsltFreeStylesheet(xslt);
00088         return 1;
00089 #else
00090         return 0;
00091 #endif
00092 }
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Defines