[xsl] XSLT 1.0 - are parentless elements in a node-set siblings?

Subject: [xsl] XSLT 1.0 - are parentless elements in a node-set siblings?
From: "Andrew Welch" <andrew.j.welch@xxxxxxxxx>
Date: Mon, 10 Dec 2007 16:06:07 +0000
Given:

<foo>
 <baz>a</baz>
 <baz>b</baz>
 <baz>a</baz>
 <baz>b</baz>
</foo>

and a stylesheet that finds unique values using the preceding axis on
a node-set:

<xsl:stylesheet
    xmlns:exslt="http://exslt.org/common";
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform"; version="1.0">

    <xsl:variable name="baz-rtf">
        <xsl:copy-of select="//baz"/>
    </xsl:variable>

    <xsl:variable name="baz" select="exslt:node-set($baz-rtf)"/>

    <xsl:template match="/">
        <xsl:for-each select="$baz/baz[not(. = preceding::baz)]">
            <xsl:value-of select="."/>
        </xsl:for-each>
    </xsl:template>

</xsl:stylesheet>

Xalan produces:

"abab"

whilst Saxon 6.5.5 gives (the expected result):

"ab"

It seems to be because the elements copied to "baz-rtf" don't have a
common parent element, they aren't siblings in Xalan...

If I modify the rtf to have a common parent:

    <xsl:variable name="baz-rtf">
        <root>
            <xsl:copy-of select="//baz"/>
        </root>
    </xsl:variable>

then it generates the expected results using both Saxon and Xalan...

Which is correct in this case?

cheers
andrew

Current Thread