Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 1st, 2012, 10:41 AM
Authorized User
 
Join Date: Sep 2012
Posts: 35
Thanks: 18
Thanked 0 Times in 0 Posts
Default XTDE0410: Cannot create an attribute node after creating ...

Hello,

I've extracted this from my XSLT :
Code:
<xsl:element name="resource"><xsl:text>&#xa;</xsl:text>
    <xsl:variable name="OnTime" select="Resource:checkOnTime($resource, xs:string('PX8'), xs:integer(8))" as="xs:boolean"/>
    <xsl:variable name="OffTime" select="Resource:checkOffTime($resource, xs:string('PX8'), xs:integer(7))" as="xs:boolean"/>
    <xsl:if test="$OffTime or $OnTime">
        <xsl:element name="errors"><xsl:text>&#xa;</xsl:text>
            <xsl:variable name="errors"  select="Resource:getErrors($resource)"/>
            <xsl:variable name="count" select="Errors:getCount($errors)"/>
            <xsl:for-each select="0 to ($count -1)">
                <xsl:variable name="error" select="Errors:getError($errors, .)"/>
                <xsl:element name="error"><xsl:text>&#xa;</xsl:text>
                    <xsl:attribute name="id" select="Error:getID($error)"/>
                    <xsl:attribute name="severity" select="Error:getSeverity($error)"/>
                    <xsl:value-of select="Error:getDescription($error)"/>
                </xsl:element><xsl:text>&#xa;</xsl:text>
            </xsl:for-each>
        </xsl:element><xsl:text>&#xa;</xsl:text>
    </xsl:if>
</xsl:element>
Where $resource is a POJO class instance passed to the XSLT as a parameter. But when I run this transformation I get this error.
Code:
Error at xsl:if on line 235 
  XTDE0410: Cannot create an attribute node after creating a child of the containing element net.sf.saxon.s9api.SaxonApiException
*** the remainder removed for brevity ***
I am at a loss as to why such an error would be generated as I am clearly not creating an attribute but an element (as allowed by the Schema), and the creation of this element is of course subject to the outcome of the offending <xsl:if />

Can anyone shed some light on this for me please?

--
William
 
Old December 1st, 2012, 11:23 AM
samjudson's Avatar
Friend of Wrox
 
Join Date: Aug 2007
Posts: 2,128
Thanks: 1
Thanked 189 Times in 188 Posts
Default

The error is because you are creating an element, then adding text to it, then trying to add an attribute to it. You need to add the attributes first:

Code:
<xsl:element name="error">
    <xsl:attribute name="id" select="Error:getID($error)"/>
    ... other attributes ...
    <xsl:text>&#xa;</xsl:text>
    ... etc
__________________
/- Sam Judson : Wrox Technical Editor -/

Think before you post: What have you tried?
The Following User Says Thank You to samjudson For This Useful Post:
WilliamYou (December 1st, 2012)
 
Old December 1st, 2012, 11:48 AM
Authorized User
 
Join Date: Sep 2012
Posts: 35
Thanks: 18
Thanked 0 Times in 0 Posts
Default

Quote:
Originally Posted by samjudson View Post
The error is because you are creating an element, then adding text to it, then trying to add an attribute to it. You need to add the attributes first:

Code:
<xsl:element name="error">
    <xsl:attribute name="id" select="Error:getID($error)"/>
    ... other attributes ...
    <xsl:text>&#xa;</xsl:text>
    ... etc
Excellent Sam. Thank you very much, I'd over done the formatting.

--
William





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to just get one node attribute value from duplicate node JohnKiller XSLT 3 December 9th, 2011 10:49 AM
How to pass node attribute? gopalbaliga XSLT 1 May 16th, 2011 06:43 AM
Get a node value using attribute name IronStar XSLT 4 May 29th, 2008 04:28 PM
to get Distinct Node depending on attribute value chaitanyaXML XML 5 March 29th, 2005 10:26 AM
How can I get the element node of an attribute cdias XSLT 2 March 15th, 2004 10:34 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.