Subject: Re: [xsl] getting "Cannot create an attribute node (...) whose parent is a document node" when copying attribute nodes through an XSLT function From: "Chris Papademetrious christopher.papademetrious@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Date: Wed, 1 Jul 2020 00:53:56 -0000 |
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@xxxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Sent: Tuesday, June 30, 2020 12:19 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx 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 whatbs happening is that, because your function doesnbt declare its return type, what itbs returning is wrapped in a document node and you canbt do that with attributes. -----Original Message----- From: Graydon graydon@xxxxxxxxx <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> Sent: Tuesday, June 30, 2020 12:17 PM To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx 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.papademetrious@xxxxxxxxxxxx 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()*".
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] getting "Cannot create an, Norman Tovey-Walsh n | Thread | |
Re: [xsl] getting "Cannot create an, Norman Tovey-Walsh n | Date | |
Month |