Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > XML > XSLT
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 1st, 2012, 10:41 AM
Authorized User
Points: 141, Level: 2
Points: 141, Level: 2 Points: 141, Level: 2 Points: 141, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
Reply With Quote
  #2 (permalink)  
Old December 1st, 2012, 11:23 AM
samjudson's Avatar
Friend of Wrox
Points: 8,687, Level: 40
Points: 8,687, Level: 40 Points: 8,687, Level: 40 Points: 8,687, Level: 40
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2007
Location: Newcastle, , United Kingdom.
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?
Reply With Quote
The Following User Says Thank You to samjudson For This Useful Post:
WilliamYou (December 1st, 2012)
  #3 (permalink)  
Old December 1st, 2012, 11:48 AM
Authorized User
Points: 141, Level: 2
Points: 141, Level: 2 Points: 141, Level: 2 Points: 141, Level: 2
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
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
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 03:43 PM.


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