The conversion to HTML creates proper XHTML.
[xmldoc.git] / xp.c
diff --git a/xp.c b/xp.c
index e56e35a..fd997d4 100644 (file)
--- a/xp.c
+++ b/xp.c
@@ -23,9 +23,6 @@
 #include <libxml/debugXML.h>
 #include <libxml/HTMLtree.h>
 #include <libxml/xmlIO.h>
-#ifdef LIBXML_DOCB_ENABLED
-#include <libxml/DOCBparser.h>
-#endif
 #ifdef LIBXML_XINCLUDE_ENABLED
 #include <libxml/xinclude.h>
 #endif
@@ -68,15 +65,13 @@ static int docbook = 0;
 #ifdef LIBXML_HTML_ENABLED
 static int html = 0;
 #endif
-#ifdef LIBXML_XINCLUDE_ENABLED
-static int xinclude = 0;
-#endif
-static int profile = 0;
 
 static const char *params[16 + 1];
 static int nbparams = 0;
 static const char *output = NULL;
 
+void LatexEscape(xmlNodePtr node);
+
 /*
  *  The LaTeX translation table. Translate unicodes to LaTeX escape sequences.
  */
@@ -351,17 +346,16 @@ static void
 xsltProcess(xmlDocPtr doc, xsltStylesheetPtr cur, const char *filename) {
     xmlDocPtr res;
 
-#ifdef LIBXML_XINCLUDE_ENABLED
-    if (xinclude) {
-       xmlXIncludeProcess(doc);
+    xmlXIncludeProcessFlags(doc, XSLT_PARSE_OPTIONS);
+
+    if (latex)
+    {
+       LatexEscape(xmlDocGetRootElement(doc));
     }
-#endif
+
     if (output == NULL) {
-       if (profile) {
-           res = xsltProfileStylesheet(cur, doc, params, stderr);
-       } else {
-           res = xsltApplyStylesheet(cur, doc, params);
-       }
+       res = xsltApplyStylesheet(cur, doc, params);
+
        xmlFreeDoc(doc);
        if (res == NULL) {
            fprintf(stderr, "no result for %s\n", filename);
@@ -415,8 +409,8 @@ void LatexEscape(xmlNodePtr node)
    if (xmlNodeIsText(node))
    {
 #ifdef DEBUG
-      fprintf(stderr, "\n-------- Text node (%d bytes):\n%s",
-                      strlen(node->content), node->content);
+      fprintf(stderr, "\n-------- Text node at %p (%d bytes):\n%s",
+                      node, strlen(node->content), node->content);
 #endif
 
       textlen = strlen(node->content);
@@ -501,7 +495,7 @@ void LatexEscape(xmlNodePtr node)
    {
       for (child = node->children; child != 0; child = child->next)
       {
-         if (strcmp(child->name, "verbatim") != 0)
+         if (strcmp(child->name, "verbatim") != 0 )
          {
             LatexEscape(child);
          }
@@ -535,10 +529,6 @@ static void usage(const char *name)
     printf("\t             otherwise XML Catalogs starting from \n");
     printf("\t         file:///etc/xml/catalog are activated by default\n");
 #endif
-#ifdef LIBXML_XINCLUDE_ENABLED
-    printf("\t--xinclude : do XInclude processing on document intput\n");
-#endif
-    printf("\t--profile or --norman : dump profiling informations \n");
 }
 
 int
@@ -597,22 +587,11 @@ main(int argc, char **argv)
         } else if ((!strcmp(argv[i], "-noout")) ||
                    (!strcmp(argv[i], "--noout"))) {
             noout++;
-#ifdef LIBXML_DOCB_ENABLED
-        } else if ((!strcmp(argv[i], "-docbook")) ||
-                   (!strcmp(argv[i], "--docbook"))) {
-            docbook++;
-#endif
 #ifdef LIBXML_HTML_ENABLED
         } else if ((!strcmp(argv[i], "-html")) ||
                    (!strcmp(argv[i], "--html"))) {
             html++;
 #endif
-        } else if ((!strcmp(argv[i], "-profile")) ||
-                   (!strcmp(argv[i], "--profile"))) {
-            profile++;
-        } else if ((!strcmp(argv[i], "-norman")) ||
-                   (!strcmp(argv[i], "--norman"))) {
-            profile++;
         } else if ((!strcmp(argv[i], "-nonet")) ||
                    (!strcmp(argv[i], "--nonet"))) {
             xmlSetExternalEntityLoader(xmlNoNetExternalEntityLoader);
@@ -628,12 +607,6 @@ main(int argc, char **argv)
                 xmlLoadCatalogs(catalogs);
             }
 #endif
-#ifdef LIBXML_XINCLUDE_ENABLED
-        } else if ((!strcmp(argv[i], "-xinclude")) ||
-                   (!strcmp(argv[i], "--xinclude"))) {
-            xinclude++;
-            xsltSetXIncludeDefault(1);
-#endif
         } else if ((!strcmp(argv[i], "-param")) ||
                    (!strcmp(argv[i], "--param"))) {
             i++;
@@ -660,6 +633,7 @@ main(int argc, char **argv)
     }
     params[nbparams] = NULL;
 
+    xsltSetXIncludeDefault(1);
     /*
      * Replace entities with their content.
      */
@@ -730,20 +704,11 @@ main(int argc, char **argv)
                 doc = htmlParseFile(argv[i], NULL);
             else
 #endif
-#ifdef LIBXML_DOCB_ENABLED
-            if (docbook)
-                doc = docbParseFile(argv[i], NULL);
-            else
-#endif
                 doc = xmlParseFile(argv[i]);
             if (doc == NULL) {
                 fprintf(stderr, "unable to parse %s\n", argv[i]);
                 continue;
             }
-            if (latex)
-            {
-               LatexEscape(xmlDocGetRootElement(doc));
-            }
            xsltProcess(doc, cur, argv[i]);
         }
     }