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 19:54:02
Hi Norman and Graydon,

This was indeed the issue. I added as="attribute()" to the function parameter 
and variable inside the function, and it works perfectly!

Many thanks,

 - Chris


-----Original Message-----
From: Norman Tovey-Walsh ndw(_at_)nwalsh(_dot_)com 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> 
Sent: Tuesday, June 30, 2020 12:19 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] getting "Cannot create an attribute node (...) whose parent 
is a document node" when copying attribute nodes through an XSLT function

    <!-- make a copy of the attributes (a proxy for processing) and return 
them -->
    <xsl:function name="mine:recopy">

Try <xsl:function name="mine:recopy" as="attribute()*">

I think what’s happening is that, because your function doesn’t declare its 
return type, what it’s returning is wrapped in a document node and you can’t do 
that with attributes.


-----Original Message-----
From: Graydon graydon(_at_)marost(_dot_)ca 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> 
Sent: Tuesday, June 30, 2020 12:17 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] getting "Cannot create an attribute node (...) whose parent 
is a document node" when copying attribute nodes through an XSLT function

On Tue, Jun 30, 2020 at 04:10:23PM -0000, Chris Papademetrious 
christopher(_dot_)papademetrious(_at_)synopsys(_dot_)com scripsit:
I'm trying to pass attribute nodes from an element template to a 
function, make a modified copy of the attributes inside the function, 
then return them for inclusion in the element. But when I attempt 
this, I get

Cannot create an attribute node (class) whose parent is a document node.

You put the attributes in a variable:

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

By default, any untyped variable will be created as a document node.

You avoid that by using "as" to specify a type, specifically that this variable 
is a sequence of one or more attributes:

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

(Possibly zero or more, which would make it "attribute()*".

--~----------------------------------------------------------------
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>