Re: [xml] Possible bug : inconsistency between xsl:copy-of, namespaces and xsd validation
- From: Agustín Villena <avillena tutopia com>
- To: <xml gnome org>
- Subject: Re: [xml] Possible bug : inconsistency between xsl:copy-of, namespaces and xsd validation
- Date: Wed, 15 Sep 2004 10:43:04 -0400
Hi!
In my last post I attached a TGZ with all example files
By the way,
The input XML to be transformed is
=============================
<!--signature-minimal.xml -->
<?xml version="1.0" encoding="UTF-8"?>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#"/>
=============================
the XSL is
=============================
<!--copy-of-xsd-bug.xsl -->
<?xml version="1.0" encoding="ISO-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="xml" version="1.0" encoding="ISO-8859-1"
omit-xml-declaration="no" standalone="yes" indent="yes"/>
<xsl:variable name="idDTE" select="string('T33F100')"/>
<xsl:template match="/">
<DTE xmlns="http://www.sii.cl/SiiDte">
<Documento ID="{$idDTE}"/>
<xsl:copy-of select="."/>
</DTE>
</xsl:template>
</xsl:stylesheet>
======================================
Note the "xsl:copy-of" function that copies the "signature" element from the
first XML.
the validation XSD files are
======================================
<!--DTE-minimal.xsd -->
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema targetNamespace="http://www.sii.cl/SiiDte"
xmlns:SiiDte="http://www.sii.cl/SiiDte"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:import namespace="http://www.w3.org/2000/09/xmldsig#"
schemaLocation="signature-minimal.xsd"/>
<xs:element name="DTE">
<xs:complexType>
<xs:sequence>
<xs:element name="Documento">
<xs:complexType>
<xs:attribute name="ID" type="xs:ID" use="required"/>
</xs:complexType>
</xs:element>
<xs:element ref="ds:Signature"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
======================================
<!--signature-minimal.xsd -->
<?xml version="1.0" encoding="ISO-8859-1"?>
<xs:schema targetNamespace="http://www.w3.org/2000/09/xmldsig#"
xmlns:ds="http://www.w3.org/2000/09/xmldsig#"
xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"
attributeFormDefault="unqualified">
<xs:element name="Signature" type="ds:SignatureType">
<xs:annotation>
<xs:documentation>Envio de Documentos Tributarios
Electronicos</xs:documentation>
</xs:annotation>
</xs:element>
<xs:complexType name="SignatureType">
<xs:annotation>
<xs:documentation>Firma Digital con Restricciones</xs:documentation>
</xs:annotation>
</xs:complexType>
</xs:schema>
======================================
And the bug example program is
======================================
/* copy-of-xsd-bug.c */
#include <libxml/xmlIO.h>
#include <libxslt/xslt.h>
#include <libxslt/xsltInternals.h>
#include <libxslt/transform.h>
#include <libxslt/xsltutils.h>
#include <libexslt/exslt.h>
#include <libxml/xmlschemas.h>
#include <libxml/xmlschemastypes.h>
int main(int argc, char * argv[])
{
xmlDocPtr transformedDoc = NULL;
/* libXSLT setup */
exsltRegisterAll();
xmlSubstituteEntitiesDefault(1);
/*XSL Transformation*/
{
xmlDocPtr styleDoc =
xmlReadFile("copy-of-xsd-bug.xsl","",XML_PARSE_NOBLANKS);
xsltStylesheetPtr style = xsltParseStylesheetDoc(styleDoc);
xmlDocPtr inputDoc =
xmlReadFile("signature-minimal.xml","",XML_PARSE_NOBLANKS);
const char *params[1]; params[0] = NULL;
transformedDoc = xsltApplyStylesheet(style, inputDoc, params);
xmlFreeDoc(inputDoc);
xmlFreeDoc(styleDoc);
}
/*XSD Compilation */
{
xmlSchemaParserCtxtPtr parserContext =
xmlSchemaNewParserCtxt("DTE-minimal.xsd");
xmlSchemaPtr schema = xmlSchemaParse(parserContext);
int validationResult;
xmlSchemaFreeParserCtxt(parserContext);
/* XSD Validation (In Memory) */
{
xmlSchemaValidCtxtPtr validationContext = xmlSchemaNewValidCtxt(schema);
validationResult = xmlSchemaValidateDoc(validationContext,
transformedDoc);
fprintf(stderr,"In memory validation return Code =
%d\n",validationResult);
xmlSchemaFreeValidCtxt(validationContext);
}
/* XSD Validation (From disk) */
xmlSaveFile("temporal.xml",transformedDoc);
{
xmlDocPtr diskDoc = xmlReadFile("temporal.xml","",XML_PARSE_NOBLANKS);
xmlSchemaValidCtxtPtr validationContext = xmlSchemaNewValidCtxt(schema);
validationResult = xmlSchemaValidateDoc(validationContext, diskDoc);
fprintf(stderr,"From disk validation return Code =
%d\n",validationResult);
xmlSchemaFreeValidCtxt(validationContext);
}
}
/* libXSLT teardown */
xsltCleanupGlobals();
}
======================================
Thanks for your great work!
Agustin
----- Original Message -----
From: "Daniel Veillard" <veillard redhat com>
To: "Agustín Villena" <avillena tutopia com>
Cc: <>
Sent: Wednesday, September 15, 2004 10:02 AM
Subject: Re: [xml] Possible bug : inconsistency between
xsl:copy-of,namespaces and xsd validation
On Wed, Sep 15, 2004 at 09:50:33AM -0400, Agustín Villena wrote:
Hi!
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
from
libxml 2.6.13, and libxslt 1.1.10
The next XML is the result of the XSL transformation
<?xml version="1.0" encoding="ISO-8859-1"?>
<DTE xmlns="http://www.sii.cl/SiiDte">
<Documento ID="T33F100"/>
<Signature xmlns="http://www.w3.org/2000/09/xmldsig#"/>
</DTE>
The "Signature" element was created using xsl:copy-of
xsl:copy-of what ? in what context ?
The problem is when I validate the resulting in-memory doc from the
transformation, the validation fails. I trace back the problem to
xmlschemas.cl, line 13200+
if (child->ns != NULL)
nsUri = child->ns->href;
When "child" is the Signature element, the namespace obtained is
"http://www.sii.cl/SiiDte", instead of the expected
http://www.w3.org/2000/09/xmldsig#
[...]
I traced back the problem to libxslt's transform.c, at the
implementation of
xslCopyOf, more exactly at xsltCopyTree / xmlNewNs part, which seems to
not
copy the namespace declared in the Signature node to the xmlNode's ns
field
(which is the examinated in the schema validation routine), but to
node's
nsDef field
line 1039
xmlNewNs(copy, (*cur)->href, (*cur)->prefix);
Since my limited knowdlege of namespace handling iin libxml, I'm not
really
sure if the problem is in xsl:copy-of or in the namespace checking part
of
XSD validation. Therefor I attach a sample program that exemplifies the
inconsitency between "in memory" and "from disk" validation of the same
transformed doc.
Any help will be really appreciated
Trying to debug a namespace XSLT generation without the stylesheet
producing it is a hopeless task. We need more info !
Daniel
--
Daniel Veillard | Red Hat Desktop team http://redhat.com/
veillard redhat com | libxml GNOME XML XSLT toolkit http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/
_______________________________________________
xml mailing list, project page http://xmlsoft.org/
xml gnome org
http://mail.gnome.org/mailman/listinfo/xml
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]