'Re: "Re: [xml] Possible bug : inconsistency between xsl:copy-of, namespaces and xsd validation"'


on 9/15/2004 4:43 PM Agustín Villena wrote:

    In my last post I attached a TGZ with all example files

[... snipp (example files)]

On Wed, Sep 15, 2004 at 09:50:33AM -0400, Agustín Villena wrote:

   I'm developing a series of xsl function extensions which implements
xmldsig signatures. My client need that any transformed document pass
through a schema validation. I'm using the new XSD schema validation
libxml 2.6.13, and libxslt 1.1.10


I traced back the problem to libxslt's transform.c, at the
implementation of
xslCopyOf, more exactly at xsltCopyTree / xmlNewNs part, which seems to
copy the namespace declared in the Signature node to the xmlNode's ns

node->ns points to a otherNode->nsDef (a chained list of xmlNs structs).

(which is the examinated in the schema validation routine), but to
nsDef field

line 1039
xmlNewNs(copy, (*cur)->href, (*cur)->prefix);

Copying the nsDef(s) is OK, since this is where they are declared; this 
is the reason why the serialized representation had it's ns declarations 
in the right place.

The devil seems to dwell in line 1020+:
     if (node->ns != NULL)
         copy->ns = xsltGetNamespace(ctxt, node, node->ns, copy);
xsltGetNamespace calls xmlSearchNs, which searches an aquivalent 
namespace by prefix; since the nsDef(s) (ns declarations) are not copied 
yet, it cannot find the correct one.

It appears to be a timing issue of first calling xsltGetNamespace, 
before the nsDefs are copied:

line 1038+:
     xmlNewNs(copy, (*cur)->href, (*cur)->prefix);
and line 1048+:
     xsltCopyNamespaceListInternal(copy, node->nsDef);

Additionally a more robust check is needed in namespaces.c
(xsltGetNamespace), line 439+:

ret = xmlSearchNs(out->doc, out, ns->prefix);
if ((ret == NULL) && (ns->prefix != NULL))
     ret = xmlSearchNsByHref(out->doc, out, URI);

The above performs a search by prefix only; a check for equal namespace 
needs to be added.



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