An XQuery document node test with the node test tag in BaseX 8.2 throws when there are comments before the root element. What for?

In BaseX 8.2, I try to assign an XQuery variable, a node document whose root element has a specific name. The source XML is as follows:

<?xml version="1.0" encoding="utf-8"?>
<!--A comment-->
<myRootElement/>

To get the node document, I will print it using DocumentTest:

declare variable $docnode as document-node(element(myRootElement)) := doc("pathToSourceFile");

However, I get the following error message: XPTY0004: Cannot process document-node () as document-node (document-node () (myRootElement)) ...

This is rather unexpected because the assignment completed successfully if there are no comments before the root <myRootElement> element. This means that having a comment causes the request to fail.

, XQuery , XSLT (, , ). XSLT, ( .671 ¶6 XSLT 2.0 XPath 2.0 4th Ed.) DocumentTest :

node , XML-. , node node, , . node.

, , XML, :

<xsl:transform version="3.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
  <xsl:output method="xml" encoding="utf-8"/>

  <xsl:template match="/">
    <xsl:variable name="docnode" as="document-node(element(myRootElement))" select="."/>
    <xsl:value-of select="$docnode/*/name(.)"/>
  </xsl:template>

</xsl:transform>

docnode , :

<?xml version="1.0" encoding="utf-8"?>myRootElement

, DocumentTest ElementTest XML- Saxon, BaseX? , - , XQuery.

+4
1

, . 8.2.1 . , .

+1

All Articles