xsl-list
[Top] [All Lists]

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

2020-06-30 11:17:03
Am 30.06.2020 um 18:10 schrieb Chris Papademetrious
christopher(_dot_)papademetrious(_at_)synopsys(_dot_)com:
        <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.
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>