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 November 12th, 2010, 10:13 AM
Authorized User
 
Join Date: Nov 2010
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default node-set question.

Hi,

I construct a node-set with the following code. I am using saxon9ee.

Code:
<xsl:variable name="countriesSortedRTF">
  <xsl:when test="$sortColumn = 'CC'">
    <xsl:for-each select="$countries">
      <xsl:sort select="@CC" order="{$sortDirection}" />
      <xsl:copy-of select=".|@*" /> <!-- Line 58 -->
    </xsl:for-each> 
  </xsl:when>
</xsl:variable>

<xsl:variable name="countriesSorted" select="$countriesSortedRTF/CTRY"/>
I get the following error:
Code:
Error at xsl:copy-of on line 58 of commonheader.xsl:
  XTDE0420: Cannot create an attribute node (id) whose parent is a document node. Most
  recent element start tag was output at line 58 of module commonheader.xsl
  at xsl:for-each (file:/C:/ReportsXSLT2_0/bin/com/display/domain/templates/commonheader.xsl#56)
Could someone explain the meaning of this error? I'm a bit lost. Thanks a lot.
 
Old November 12th, 2010, 10:20 AM
Friend of Wrox
 
Join Date: Nov 2007
Posts: 1,243
Thanks: 0
Thanked 245 Times in 244 Posts
Default

I guess you simply want
Code:
<xsl:copy-of select="."/>
as that makes a deep copy of each node you process in the for-each. Currently you are copying each node and each of its attributes and you can put an attribute node in a document (which a variable set up as you do is).
__________________
Martin Honnen
Microsoft MVP (XML, Data Platform Development) 2005/04 - 2013/03
My blog
 
Old November 12th, 2010, 01:05 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

xsl:when is not allowed as a child of xsl:variable, so I don't see how you could possibly have got this error with this code.
__________________
Michael Kay
http://www.saxonica.com/
Author, XSLT 2.0 and XPath 2.0 Programmer\'s Reference
 
Old November 15th, 2010, 11:35 AM
Authorized User
 
Join Date: Nov 2010
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks Martin. That did the trick.

It was important for me to keep the attributes, but as you say since it is a deep copy they were copied anyway but now they are not copied for the document node.





Similar Threads
Thread Thread Starter Forum Replies Last Post
XPath: set operation with a disjoint node set rich_unger XSLT 7 May 6th, 2008 09:24 AM
Expression must evaluate to a node-set. XMLUser XSLT 3 February 5th, 2008 01:27 PM
Converting String into Node-set dved XSLT 3 January 23rd, 2008 12:40 PM
Filtering out from a node set anothervbaddict XSLT 1 May 22nd, 2007 08:42 AM
node-set function Bernardo Pacheco XSLT 2 June 19th, 2006 10:45 AM





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