Sablotron 0.4 will output duplicate namespace declarations, e.g:

Given this stylesheet:

<?xml version="1.0"?>
<!DOCTYPE xsl:stylesheet[
 <!ENTITY nl  "<xsl:text>&#xA;</xsl:text>">
]>
<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="/*">
    &nl;<foo:x xmlns:foo="http://www.kitsite.com/">&nl;
      <foo:y/>&nl;
    </foo:x>&nl;
  </xsl:template>

</xsl:stylesheet>


Applied to this document: <foo/>

We get this output:

<?xml version="1.0" encoding="UTF-8"?>
<foo:x xmlns:foo="http://www.kitsite.com/">
<foo:y xmlns:foo="http://www.kitsite.com/" xmlns:foo="http://www.kitsite.com/"/>
</foo:x>


Which is not even well-formed XML because it has a duplicate attribute.

The attached patch will fix the problem, but the output is still
over-enthusiastic. The namespace declaration need only appear in
the outer element.

 .robin.

-- 
Are we not drawn onward, we few, drawn onward to new era?
diff -Naur Sablot-0.40/Sablot/output.cpp Sablot-0.40-patched/Sablot/output.cpp
--- Sablot-0.40/Sablot/output.cpp       Fri Jun 30 11:23:25 2000
+++ Sablot-0.40-patched/Sablot/output.cpp       Fri Jun 30 17:57:46 2000
@@ -278,7 +278,8 @@
 }
 
 eFlag PhysicalOutputLayerObj::outputElementStart(const Str& name,
-    const StrStrList& namespaces, const QNameStrList& atts, Bool isEmpty)
+    const StrStrList& namespaces, const int namespace_index,
+    const QNameStrList& atts, Bool isEmpty)
 {
     // begin output of start tag: output element name
 
@@ -289,7 +290,7 @@
 
     int i;
     const Str* prefix;
-    for (i = 0; i < namespaces.number(); i++)
+    for (i = namespace_index; i < namespaces.number(); i++)
     {
         sendLit(" xmlns");
         prefix = &(namespaces[i] -> key);
@@ -1128,7 +1129,7 @@
         return OK;
     if (physical)
         E( physical -> outputElementStart(currElement.getname(), 
-        currNamespaces, currAtts, isEmpty) );
+        currNamespaces, getFirstOwnNS(), currAtts, isEmpty) );
     if (mySAXHandler)
     {
         const char**
diff -Naur Sablot-0.40/Sablot/output.h Sablot-0.40-patched/Sablot/output.h
--- Sablot-0.40/Sablot/output.h Fri Jun 30 11:23:25 2000
+++ Sablot-0.40-patched/Sablot/output.h Fri Jun 30 17:53:50 2000
@@ -111,7 +111,8 @@
     ~PhysicalOutputLayerObj();
     eFlag setOptions(DataLine *targetDataLine_, OutputDefinition *outDef_);
     eFlag outputElementStart(const Str& name, 
-        const StrStrList& namespaces, const QNameStrList& atts, Bool isEmpty);
+        const StrStrList& namespaces, const int namespace_index,
+        const QNameStrList& atts, Bool isEmpty);
     eFlag outputElementEnd(const Str& name, Bool isEmpty);
     eFlag outputText(const Str& contents, Bool outputEscaping, Bool inHTMLSpecial);
     eFlag outputComment(const Str& contents);

Reply via email to