943,891 Members | Top Members by Rank

Ad:
Feb 11th, 2009
0

copy root node - urgent

Expand Post »
I really need help in copying the root node.

I have been spending far too much time on this, and I can't beleive that it should be that difficult. I can't use 'copy-of', as that will copy all the children as well. I need to copy the root node, and it's attributes. This is what I currently have:

XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:pre="http://schemas.namespace.org/myschema/myschame.xsd">
  3. <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
  4.  
  5. <xsl:template match="/">
  6. <xsl:element name="{name()}">
  7. <xsl:apply-templates select="pre:Msg" />
  8. </xsl:element>
  9. </xsl:template>
  10.  
  11. <xsl:template match="pre:Msg">
  12.  
  13.  
  14. <xsl:for-each select="pre:Record">
  15.  
  16. <xsl:sort select="pre:ReplaceRecord/pre:Id/pre:Number" />
  17. <xsl:sort select="pre:EventSequenceNumber" data-type="number"/>
  18. <xsl:copy-of select="." />
  19. </xsl:for-each>
  20.  
  21.  
  22. </xsl:template>
  23.  
  24. </xsl:stylesheet>

The above xsl will thow an error. It has something to do with namespaces. The error is:

An attribute whose value must be a QName had the value ''

I have tried using the namespace attribute, plus a heap of other things. All I wish to do is to copy the root node. Can somebody please help me with this. Thankyou.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rat1973 is offline Offline
9 posts
since Feb 2009
Feb 11th, 2009
0

Re: copy root node - urgent

I beleive I have it now. I needed the following:

XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:pre="http://schemas.namespace.org/myschema/myschame.xsd">
  3. <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
  4.  
  5. <xsl:template match="/">
  6. <xsl:apply-templates select="pre:Msg" />
  7. </xsl:template>
  8.  
  9. <xsl:template match="pre:Msg">
  10. <xsl:copy>
  11.  
  12.  
  13. <xsl:for-each select="pre:Record">
  14.  
  15. <xsl:sort select="pre:ReplaceRecord/pre:Id/pre:Number" />
  16. <xsl:sort select="pre:EventSequenceNumber" data-type="number"/>
  17. <xsl:copy-of select="."/>
  18. </xsl:for-each>
  19.  
  20. </xsl:copy>
  21.  
  22. </xsl:template>
  23.  
  24. </xsl:stylesheet>

A case of still learning XSL.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
rat1973 is offline Offline
9 posts
since Feb 2009

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in XML, XSLT and XPATH Forum Timeline: Creating List in XSLT
Next Thread in XML, XSLT and XPATH Forum Timeline: Sorting XML





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC