@ -1,4 +1,5 @@
# include <stdio.h>
# include <string.h>
# include <libxml/xmlmemory.h>
# include <libxml/debugXML.h>
# include <libxml/HTMLtree.h>
@ -17,10 +18,13 @@ extern int xmlLoadExtDtdDefaultValue;
void init_extensions ( ) ;
/* TODO: check for parse errors */
static int error = 0 ;
/* output usage message. progname is the name of the executable. */
static void usage ( const char * progname )
{
printf ( " Usage: %s [options] stylesheet input \n " , progname ) ;
printf ( " Usage: %s [options] stylesheet input output \n " , progname ) ;
printf ( " --param name value : pass a parameter to the stylesheet \n " ) ;
}
@ -32,6 +36,7 @@ int main(int argc, char** argv)
int nbparams = 0 ;
xsltStylesheetPtr cur = NULL ;
xmlDocPtr doc , res ;
FILE * out ;
maxparams = 16 ;
params = ( const char * * ) malloc ( sizeof ( char * ) * maxparams * 2 ) ;
@ -59,7 +64,7 @@ int main(int argc, char** argv)
return 1 ;
}
}
if ( argNum = = argc ) {
if ( ( argc - argNum ) ! = 3 ) {
usage ( argv [ 0 ] ) ;
return 1 ;
}
@ -73,9 +78,18 @@ int main(int argc, char** argv)
cur = xsltParseStylesheetFile ( ( const xmlChar * ) argv [ argNum ] ) ;
argNum + + ;
doc = xmlParseFile ( argv [ argNum ] ) ;
argNum + + ;
if ( ! doc )
return 1 ;
res = xsltApplyStylesheet ( cur , doc , params ) ;
xsltSaveResultToFile ( stdout , res , cur ) ;
if ( ! res | | error )
return 1 ;
out = fopen ( argv [ argNum ] , " w " ) ;
if ( ! out )
return 1 ;
xsltSaveResultToFile ( out , res , cur ) ;
fclose ( out ) ;
xsltFreeStylesheet ( cur ) ;
xmlFreeDoc ( res ) ;
xmlFreeDoc ( doc ) ;