Re: [xsl] getting "Cannot create an attribute node (...) whose parent is a document node" when copying attribute nodes through an XSLT function

Subject: Re: [xsl] getting "Cannot create an attribute node (...) whose parent is a document node" when copying attribute nodes through an XSLT function
From: "Martin Honnen martin.honnen@xxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 30 Jun 2020 16:16:58 -0000
Am 30.06.2020 um 18:10 schrieb Chris Papademetrious
christopher.papademetrious@xxxxxxxxxxxx:
<xsl:variable name="new_atts">

<xsl:sequence select="$orig_atts"/>

</xsl:variable>


This doesn't copy the attribute nodes, it creates a document (fragment) node and tries to populate it with the $orig_atts, so that is not a meaningful approach, as document nodes or document fragment nodes can't contain attribute nodes, only element nodes can do that.

You can simply use

<xsl:variable name="new_atts" select="$orig_atts"/>

or

  <xsl:variable name="new_atts" as="attribute()*">
    <xsl:sequence select="$orig_atts"/>
  </xsl:variable>

however, that will both bind the new variable to the existing attribute
nodes. If you really need a copy, use `xsl:copy-of` instead of
`xsl:sequence` or perhaps in XSLT 3.0 the `copy-of()` function.

Current Thread