[xslt] namespace prefix missing in DOCTYPE for generated xml file



Hi,

Using xsltproc to produce content.xml for poenoffice douments I ran
into a problem:

libxslt produces DOCTYPE without the namespace for the root element.

I get a
<!DOCTYPE document-content PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "oodtd/office.dtd">
instead of
<!DOCTYPE office:document-content PUBLIC "-//OpenOffice.org//DTD OfficeDocument 1.0//EN" "oodtd/office.dtd">

I am very convinced, that the result including the namespace is
correct, as both saxon and xalan produce it the second way. Also
Openoffice(or at least some builds) goes crazy if the namespace-prefix
is missing.

I created a patch for transform.c:
When the root element has namespace then dtd element is created with
the prefix:name instead of only name.

Bye Christian
--- libxslt/transform.c.orig	Sun Dec 21 13:12:04 2003
+++ libxslt/transform.c	Fri Feb  6 15:18:09 2004
@@ -2220,12 +2220,33 @@
 
         }
         if (ctxt->type == XSLT_OUTPUT_XML) {
-            XSLT_GET_IMPORT_PTR(doctypePublic, style, doctypePublic)
-                XSLT_GET_IMPORT_PTR(doctypeSystem, style, doctypeSystem)
-                if (((doctypePublic != NULL) || (doctypeSystem != NULL)))
-                res->intSubset = xmlCreateIntSubset(res, root->name,
-                                                    doctypePublic,
-                                                    doctypeSystem);
+            xmlChar * docrootname = NULL;
+            if (root->ns != NULL) {
+                int docrootlen = xmlStrlen(root->name) + 2
+                                 + xmlStrlen(root->ns->prefix);
+                docrootname = (xmlChar*) malloc(docrootlen);
+                if (docrootname)
+                    xmlStrPrintf(docrootname, docrootlen,
+                                 "%s:%s",
+                                 root->ns->prefix, root->name);
+            }
+            if (docrootname != NULL) {
+                XSLT_GET_IMPORT_PTR(doctypePublic, style, doctypePublic)
+                    XSLT_GET_IMPORT_PTR(doctypeSystem, style, doctypeSystem)
+                    if (((doctypePublic != NULL) || (doctypeSystem != NULL)))
+                    res->intSubset = xmlCreateIntSubset(res, docrootname,
+                                                        doctypePublic,
+                                                        doctypeSystem);
+                xmlFree(docrootname);
+            }
+            else {
+                XSLT_GET_IMPORT_PTR(doctypePublic, style, doctypePublic)
+                    XSLT_GET_IMPORT_PTR(doctypeSystem, style, doctypeSystem)
+                    if (((doctypePublic != NULL) || (doctypeSystem != NULL)))
+                    res->intSubset = xmlCreateIntSubset(res, root->name,
+                                                        doctypePublic,
+                                                        doctypeSystem);
+            }
         }
     }
 
@@ -4032,12 +4053,33 @@
 
         }
         if (ctxt->type == XSLT_OUTPUT_XML) {
-            XSLT_GET_IMPORT_PTR(doctypePublic, style, doctypePublic)
-                XSLT_GET_IMPORT_PTR(doctypeSystem, style, doctypeSystem)
-                if (((doctypePublic != NULL) || (doctypeSystem != NULL)))
-                res->intSubset = xmlCreateIntSubset(res, root->name,
-                                                    doctypePublic,
-                                                    doctypeSystem);
+            xmlChar * docrootname = 0;
+            if (root->ns) {
+                int docrootlen = xmlStrlen(root->name) + 2
+                                 + xmlStrlen(root->ns->prefix);
+                docrootname = (xmlChar*) malloc(docrootlen);
+                if (docrootname)
+                    xmlStrPrintf(docrootname, docrootlen,
+                                 "%s:%s",
+                                 root->ns->prefix, root->name);
+            }
+            if (docrootname) {
+                XSLT_GET_IMPORT_PTR(doctypePublic, style, doctypePublic)
+                    XSLT_GET_IMPORT_PTR(doctypeSystem, style, doctypeSystem)
+                    if (((doctypePublic != NULL) || (doctypeSystem != NULL)))
+                    res->intSubset = xmlCreateIntSubset(res, docrootname,
+                                                        doctypePublic,
+                                                        doctypeSystem);
+                xmlFree(docrootname);
+            }
+            else {
+                XSLT_GET_IMPORT_PTR(doctypePublic, style, doctypePublic)
+                    XSLT_GET_IMPORT_PTR(doctypeSystem, style, doctypeSystem)
+                    if (((doctypePublic != NULL) || (doctypeSystem != NULL)))
+                    res->intSubset = xmlCreateIntSubset(res, root->name,
+                                                        doctypePublic,
+                                                        doctypeSystem);
+            }
         }
     }
     xmlXPathFreeNodeSet(ctxt->nodeList);


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