Re: [xslt] Segmentation fault (namespace axis)



On Sun, Aug 12, 2001 at 02:06:27PM +0200, Bernhard Zwischenbrugger wrote:
> I do some work an XML - files with mixed
> xhtml an xfroms namspaces.
> 
> I think my example is wrong, but I couldn't

  a bit, yes

> find a working example and there is a seg fault.

  yep, fixed it

> Is this the place to report Segmentation fault errors?

  yes :-\

> The broken example:
> ===============
> 
> <?xml version="1.0" encoding="UTF-8"?>
> <xsl:stylesheet
>         version="1.0"
>         xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>         xmlns:libxslt="http://xmlsoft.org/XSLT/namespace"
>         xmlns:test1="http://www.test1.com"
>         xmlns:test2="http://www.test2.com"
>         >
> <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
>  
> <xsl:template match="/all/*">
>         <xsl:for-each select="namespace::*">
>                 <xsl:copy-of select="."/>
>         </xsl:for-each>
> </xsl:template>
>  
> </xsl:stylesheet>
> 
> bz@linuxdaheim:~/firma/technisches/xforms/namespaces$ more test.xml
> <?xml version="1.0"?>
> <all>
> <one xmlns="http://www.test1.com">1</one>
> <two xmlns="http://www.test2.com">2</two>
> </all>
> 
> bz@linuxdaheim:~/firma/technisches/xforms/namespaces$ xsltproc -V
> Using libxml 20400 and libxslt 10000
> xsltproc was compiled against libxml 20400 and libxslt 10000
> libxslt 10000 was compiled against libxml 20400
> 
> bz@linuxdaheim:~/firma/technisches/xforms/namespaces$ xsltproc test.xsl 
> test.xml
> Segmentation fault

  Okay I fixed this in CVS. Namespaces nodes are really different nodes
in libxml and a few checks for those were missing.

http://cvs.gnome.org/bonsai/cvsquery.cgi?module=libxslt&branch=HEAD&branchtype=match&dir=libxslt&file=&filetype=match&who=veillard&whotype=match&sortby=Date&hours=&date=explicit&mindate=08%2F12%2F01+15%3A54&maxdate=08%2F12%2F01+15%3A56&cvsroot=%2Fcvs%2Fgnome

To come back to your example here is the current result:

orchis:~/XSLT/tests/general -> xsltproc bug-54.xsl ../docs/bug-54.xml 
<?xml version="1.0" encoding="UTF-8"?>




orchis:~/XSLT/tests/general -> 

it doesn't crash anymore but don't output the expected namespaces, why ?
Simply you are doing xsl:copy-of of a namespace node while the current
insertion node is the document node. Simply adding a root element to the
target document allow to graft the new namspace nodes:

orchis:~/XSLT/tests/general -> cat bug-54.xsl
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
        version="1.0"
        xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
        xmlns:libxslt="http://xmlsoft.org/XSLT/namespace"
        xmlns:test1="http://www.test1.com"
        xmlns:test2="http://www.test2.com"
        >
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>

<xsl:template match="/all/*">
        <xsl:for-each select="namespace::*">
                <xsl:copy-of select="."/>
        </xsl:for-each>
</xsl:template>
<xsl:template match="/">
    <root>
    <xsl:apply-templates/>
    </root>
</xsl:template>

</xsl:stylesheet>
orchis:~/XSLT/tests/general -> xsltproc bug-54.xsl ../docs/bug-54.xml 
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:libxslt="http://xmlsoft.org/XSLT/namespace" xmlns:test1="http://www.test1.com" xmlns:test2="http://www.test2.com" xmlns="http://www.test1.com">


</root>
orchis:~/XSLT/tests/general -> 

  Looks better.
Last but not least, in general this is not needed at all. The XSLT engine will
generate the namespaces from the source or stylesheets needed on the generated
document automatically. In most cases you don't need to search and copy them
manually, XSLT makes sure that they are present when needed but you may
have a specific case where this is needed.

Daniel

-- 
Daniel Veillard      | Red Hat Network http://redhat.com/products/network/
veillard@redhat.com  | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/




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