You are viewing a plain text version of this content. The canonical link for it is here.
Posted to j-users@xalan.apache.org by Jens Pelzetter <je...@scientificcms.org> on 2014/09/10 15:13:29 UTC

namespace-uri XPath function does not work as expected

Hello everybody,

we are using Xalan for transforming XML document to HTML. For debugging
purposes, our applications has the possibility to output the XML instead
of the transformed HTML. If the XML is requested, the following
XSL-Stylesheet is used to generate the output:

<xsl:stylesheet version="1.0"
                xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml"/>
        <xsl:template match="text()|comment()|processing-instruction()">
            <xsl:copy/>
        </xsl:template>

        <xsl:template match="*">
            <xsl:element name="{name()}"
                         namespace="{namespace-uri()}">
                <xsl:apply-templates select="node()|@*"/>
            </xsl:element>
        </xsl:template>

        <xsl:template match="@*">
            <xsl:attribute name="{name()}"
                           namespace="{namespace-uri()}">
                <xsl:value-of select="."/>
            </xsl:attribute>
        </xsl:template>

        <xsl:template match="bebop:structure"
                      xmlns:bebop="http://www.arsdigita.com/bebop/1.0">
        </xsl:template>
</xsl:stylesheet>

After upgrading the Xalan 2.7.1/2.7.2 (including the serializer), some
attributes without a namespace are prefixed with an namespace attribute.
An stripped down example for testing:

The XML document:

<?xml version="1.0"?>
<doc:doc xmlns:doc="http://www.example.org/doc"
         date="2014-09-10"
         id="2014-09-10/48/439">

    <doc:title>Example</doc:title>

    <author:info xmlns:author="http://www.example.org/author"
                 attr1="fiadao"/>

    <doc:content status="final">Lorem ipsum</doc:content>

</doc:doc>

Result with Xalan 2.7.1 and 2.7.1:

<?xml version="1.0" encoding="UTF-8"?>
<doc:doc xmlns:doc="http://www.example.org/doc"
         date="2014-09-10"
         id="2014-09-10/48/439">

    <doc:title>
        Example
    </doc:title>

    <author:info xmlns:author="http://www.example.org/author"
attr1="fiadao"/>

    <doc:content author:status="final">
        Lorem ipsum
    </doc:content>

</doc:doc>

Result with Xalan 2.7.0 (and libxslt):

<?xml version="1.0"?>
<doc:doc xmlns:doc="http://www.example.org/doc"
         date="2014-09-10"
         id="2014-09-10/48/439">

    <doc:title>
        Example
    </doc:title>

    <author:info xmlns:author="http://www.example.org/author"
                 attr1="fiadao"/>

    <doc:content status="final">
        Lorem ipsum
    </doc:content>

</doc:doc>

The result from Xalan 2.7.1 and later produces an error (prefix not
bound the namespace) when the document is viewed in a browser, because
of the wrong(?) namespace prefix on the status attribute of the
doc:content element.

Obviously the namespace-uri function call in the third template
(match="*@") returns a wrong (?) namespace.

Is this a problem in our stylesheet/XML or something in Xalan?

Unfortunately, I can't check the changes made in the last Xalan releases
myself because the links in the release notes to the resolved issues in
Jira/Bugzilla are not working.

Thanks for help in advance and Best regards

-- 
Jens Pelzetter
Erasmusstraße 3
27404 Zeven

Tel.:   +49 4281 952459
E-Mail: jens.pelzetter@scientificcms.org
Web:    http://www.scientificcms.org