Re: [xslt] Namespace problem



Le 30/04/01 17:42:31, Bjorn Reese a écrit :
>   ns = xmlSearchNs(ctxt->doc, ctxt->elem, prefix);
> 
> There seems to be a mismatch between the two first parameters and the
> last. The two first parameters are pointing to data within the xsl
> file, but the prefix parameter contains the namespace from the xml
> file. So it tries to find the 'ns' namespace in the xsl file, starting
> from the <xsl:template match='ns:root'> line.

That's the expected behaviour.

Matching is done against the namespace URI, not the prefix.

> This was tested against the latest CVS version.
> <xsl:stylesheet
>  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
>  version="1.0">
> 
> <xsl:output method="text"/>
> 
> <xsl:template match="ns:root">
>   RIGHT
> </xsl:template>
> 
> <xsl:template match="/">
>   WRONG
> </xsl:template>
> 
> </xsl:stylesheet>

This stylesheet is invalid since the ns namespace prefix isn't declared.

xsltproc 0.5.0 (I haven't compiled any later release yet) returns:
ptittom:~$ xsltproc namespace.xsl namespace.xml 
xsl: pattern, no namespace bound to prefix ns

  WRONG

As do SAXON and Xalan:
ptittom:~$ java -cp saxon/saxon.jar com.icl.saxon.StyleSheet namespace.xml
namespace.xsl 
Error at xsl:template on line 7 of file:/home/ptittom/namespace.xsl:
  Namespace prefix ns has not been declared
Transformation failed

ptittom:~$ java -cp Fop-0.18.1-DEV/lib/xalan-2.0.0.jar:Fop-0.18.1-DEV/lib/xerces-1.2.3.jar
org.apache.xalan.xslt.Process -in namespace.xml -xsl namespace.xsl 
file:///home/ptittom/namespace.xsl; Line 7; Column 31; 
XSLT Error (javax.xml.transform.TransformerConfigurationException): Prefix
must resolve to a namespace: ns

ptittom:~$ java -cp Fop-0.18.1-DEV/lib/xalan-1.2.2.jar:Fop-0.18.1-DEV/lib/xerces-1.2.3.jar
org.apache.xalan.xslt.Process -in namespace.xml -xsl namespace.xsl 
========= Parsing file:/home/ptittom/namespace.xsl ==========
XSL Error: Could not parse file:/home/ptittom/namespace.xsl document!
XSL Error: processStylesheet not successful!
XSLT: ElemTemplateElement error: Can not resolve namespace prefix: ns
Xalan: was not successful.
XSLProcessor: done

One can notice xsltproc (maybe it has changed since 0.5.0) doesn't consider
this error a fatal error and doesn't stop processing.

Tom.




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