Duplicate IDs and function id()

Wednesday, 24 July 2024 · 2 messages · last reply 26 Jul 2024
AS
Andrew Sales24 Jul 2024 18:14 #
Hello, If I understand the spec for this function[1] correctly, at most one element should be returned for a given ID value: "If several elements have the same ID value, then E is the one that is first in document order." ("Rules", item 3) BaseX behaves differently from e.g. Saxon in this respect. The query:
let $doc := document{<foo xml:id='a1'><bar xml:id='a1'/></foo>}

return (
  'Saxon-HE 11.6:',
  xslt:transform($doc, <xsl:stylesheet xmlns:xsl="
http://www.w3.org/1999/XSL/Transform"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    exclude-result-prefixes="xs"
    version="3.0">

    <xsl:template match="/">
        <xsl:sequence select="id('a1')"/>
    </xsl:template>

</xsl:stylesheet>),
  'BaseX 10.7:',
  $doc/id('a1')
)
returns: Saxon-HE 11.6:
<foo xml:id="a1"><bar xml:id="a1"/></foo>
BaseX 10.7:
<foo xml:id="a1"><bar xml:id="a1"/></foo>
<bar xml:id="a1"/>
i.e. Saxon returns only the first in document order, whereas BaseX returns both of them. Grateful for your thoughts, Andrew [1] https://www.w3.org/TR/xpath-functions-31/#func-id
CG
Christian Grün26 Jul 2024 14:51 #
Hi Andrew, A precious observation; it appears there isn’t a single test case for that in the W3 test suite. We’ll fix it with the next release; until then, you can use head(id(...)). Thank you, Christian
Quoted text · Andrew Sales · 47 lines
On Wed, Jul 24, 2024 at 6:14 PM Andrew Sales <andrew at andrewsales.com> wrote: > Hello, > > If I understand the spec for this function[1] correctly, at most one > element should be returned for a given ID value: > > "If several elements have the same ID value, then E is the one that is > first in document order." > ("Rules", item 3) > > BaseX behaves differently from e.g. Saxon in this respect. The query: > > let $doc := document{<foo xml:id='a1'><bar xml:id='a1'/></foo>} > > return ( > 'Saxon-HE 11.6:', > xslt:transform($doc, <xsl:stylesheet xmlns:xsl=" > http://www.w3.org/1999/XSL/Transform" > xmlns:xs="http://www.w3.org/2001/XMLSchema" > exclude-result-prefixes="xs" > version="3.0"> > > <xsl:template match="/"> > <xsl:sequence select="id('a1')"/> > </xsl:template> > > </xsl:stylesheet>), > 'BaseX 10.7:', > $doc/id('a1') > ) > > returns: > > Saxon-HE 11.6: > <foo xml:id="a1"><bar xml:id="a1"/></foo> > BaseX 10.7: > <foo xml:id="a1"><bar xml:id="a1"/></foo> > <bar xml:id="a1"/> > > i.e. Saxon returns only the first in document order, whereas BaseX returns > both of them. > > Grateful for your thoughts, > Andrew > > [1] https://www.w3.org/TR/xpath-functions-31/#func-id >

⚡Generated with XQuery