#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
#include <libxslt/xsltutils.h>
#include <libxslt/extensions.h>
-#include <libexslt/exsltconfig.h>
+#include <libexslt/exslt.h>
#ifndef HAVE_STAT
const char *ID,
xmlParserCtxtPtr ctxt);
+#define LIBXML_DEBUG_ENABLED
+//#define DEBUG
+
static int debug = 0;
static int novalid = 0;
static int noout = 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.
*/
{ '$', "\\$" },
{ '%', "\\%" },
{ '&', "\\&" },
- { '<', "\\verb+<+" },
- { '>', "\\verb+>+" },
+ { '<', "$<$" },
+ { '>', "$>$" },
{ '\\', "$\\backslash$" },
- { '^', "\\verb+^+" },
+ { '^', "$\\wedge$" },
{ '_', "\\_" },
{ '{', "\\{" },
+ { '|', "$\\mid$" },
{ '}', "\\}" },
- { '~', "\\verb+~+" },
+ { '~', "$\\sim$" },
{ 160, "~" },
{ 161, "!`" },
{ 162, "..." },
xsltProcess(xmlDocPtr doc, xsltStylesheetPtr cur, const char *filename) {
xmlDocPtr res;
-#ifdef LIBXML_XINCLUDE_ENABLED
- if (xinclude) {
- xmlXIncludeProcess(doc);
- }
+ xmlXIncludeProcessFlags(doc, XSLT_PARSE_OPTIONS);
+
+#ifdef DEBUG
+ xmlDebugDumpDocument(stdout, doc);
#endif
+
+ if (latex)
+ {
+ LatexEscape(xmlDocGetRootElement(doc));
+ }
+
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);
void LatexEscape(xmlNodePtr node)
{
xmlNodePtr child;
+ xmlAttrPtr attribute;
xmlChar *byte;
int unicode;
int textlen;
int i;
+#ifdef DEBUG
+ fprintf(stderr, "\n-------- Node type %d\n", node->type);
+#endif
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);
}
else
{
+ for (attribute = node->properties; attribute != 0; attribute = attribute->next)
+ {
+ LatexEscape(attribute->children);
+ }
for (child = node->children; child != 0; child = child->next)
{
- if (strcmp(child->name, "verbatim") != 0)
+ if (strcmp(child->name, "verbatim") != 0 && strcmp(child->name, "example") != 0)
{
LatexEscape(child);
}
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
} 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);
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++;
}
params[nbparams] = NULL;
+ xsltSetXIncludeDefault(1);
/*
* Replace entities with their content.
*/
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]);
}
}