XML to XML via XSL Transform Error...

Please support our XML, XSLT and XPATH advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Sep 2009
Posts: 12
Reputation: sinnerFA is an unknown quantity at this point 
Solved Threads: 3
sinnerFA sinnerFA is offline Offline
Newbie Poster

XML to XML via XSL Transform Error...

 
0
  #1
Sep 15th, 2009
Here is a sample of the XML that I am starting with:

XML: any.xml
XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <?xml-stylesheet type="text/xsl" href="any.xsl"?>
  3. <root>
  4. <device>
  5. <device_Info>
  6. <name>Name 1</name>
  7. <type>Type</type>
  8. </device_Info>
  9. <drive_Pair>
  10. <status>Ready</status>
  11. <Local>
  12. <l_name>10E5</l_name>
  13. </Local>
  14. <Remote>
  15. <l_name>0651</l_name>
  16. </Remote>
  17. </drive_Pair>
  18. #Can be 1 or many <drive_Pair>'s
  19. {<drive_Pair>
  20. ...
  21. </drive_Pair>}
  22. # Can only be 1 Totals
  23. <Totals>
  24. <Local>
  25. <l1_invalid_mbs>0.0</l1_invalid_mbs>
  26. <l2_invalid_mbs>0.0</l2_invalid_mbs>
  27. </Local>
  28. </Totals>
  29. </device>
  30. #Can be 1 or many <device>'s
  31. {<device>
  32. ...
  33. </device>}
  34. </root>

XSL: any.xsl
XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  2. <xsl:output method="xml" version="1.0" standalone="yes" cdata-section-elements="devices" indent="yes"/>
  3. <xsl:template match="/root/device">
  4. <xsl:element name="devices">
  5. <xsl:for-each select="device_Info">
  6. <device name="{name}" type="{type}"/>
  7. </xsl:for-each>
  8. <xsl:for-each select="drive_Pair">
  9. <drive_Pair status="{status}" local="{Local/l_name}" remote="{Remote/l_name}"/>
  10. </xsl:for-each>
  11. <xsl:for-each select="drive_Pair_Totals/Local">
  12. <Totals l1="{l1_invalid_mbs}" l2="{l2_invalid_mbs}"/>
  13. </xsl:for-each>
  14. </xsl:element>
  15. </xsl:template>
  16. </xsl:stylesheet>

The XML Result: temp.xml
XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1. <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
  2. <devices>
  3. <device name="Name 1" type="backup"/>
  4. <drive_Pair status="same" local="1234" remote="1234"/>
  5. <drive_Pair status="same" local="4321" remote="4321"/>
  6. <Totals l1="0.0" l2="0.0"/>
  7. </devices>
  8. <devices>
  9. <device name="Name 2" type="Active"/>
  10. <drive_Pair status="different" local="3425" remote="3542"/>
  11. <drive_Pair status="different" local="0362" remote="9876"/>
  12. <drive_Pair status="same" local="8767" remote="8767"/>
  13. <Totals l1="0.0" l2="0.0"/>
  14. </devices>

The issue I am having is when I validate the output XML, temp.xml it comes back with an error that happens right here (line 8 of temp.xml):
XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1. <Totals l1="0.0" l2="0.0"/>
  2. </devices>
  3. <devices> #<--------- "Character 'D' is grammatically unexpected"
  4. <device name="Name 2" type="Active"/>

It references that the reason for the error is because it expects '!' or '?'.... And I am at a loss on how to "fix" it.
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 824
Reputation: pritaeas will become famous soon enough pritaeas will become famous soon enough 
Solved Threads: 135
Sponsor
pritaeas's Avatar
pritaeas pritaeas is online now Online
Practically a Posting Shark

Re: XML to XML via XSL Transform Error...

 
0
  #2
Sep 15th, 2009
An XML document needs exactly one root element. So you should wrap your devices tags in another tag.
See: http://en.wikipedia.org/wiki/Root_element
"If it is NOT source, it is NOT software."
-- NASA
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 44
Reputation: xml_looser is an unknown quantity at this point 
Solved Threads: 2
xml_looser xml_looser is offline Offline
Light Poster

Re: XML to XML via XSL Transform Error...

 
1
  #3
Sep 15th, 2009
XML, XSLT and XPATH Syntax (Toggle Plain Text)
  1. <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  2. <xsl:output method="xml" version="1.0" standalone="yes" cdata-section-elements="devices" indent="yes"/>
  3. <xsl:template match="root">
  4. <devices>
  5. <xsl:apply-templates select="device"/>
  6. </devices>
  7. </xsl:template>
  8.  
  9. <xsl:template match="device">
  10. <xsl:apply-templates select="device_Info"/>
  11. <xsl:apply-templates select="drive_Pair"/>
  12. <xsl:apply-templates select="Totals"/>
  13. </xsl:template>
  14.  
  15.  
  16. <xsl:template match="device_Info">
  17. <device name="{name}" type="{type}"/>
  18. </xsl:template>
  19. <xsl:template match="drive_Pair">
  20. <drive_Pair status="{status}" local="{Local/l_name}" remote="{Remote/l_name}"/>
  21. </xsl:template>
  22.  
  23.  
  24. <xsl:template match="Totals">
  25. <Totals l1="l1_invalid_mbs" l2="l2_invalid_mbs"/>
  26. </xsl:template>
  27. </xsl:stylesheet>
Reply With Quote Quick reply to this message  
Join Date: Sep 2009
Posts: 12
Reputation: sinnerFA is an unknown quantity at this point 
Solved Threads: 3
sinnerFA sinnerFA is offline Offline
Newbie Poster

Re: XML to XML via XSL Transform Error...

 
0
  #4
Sep 15th, 2009
Thanks for both replies, I had setup a rootElement earlier and It kept giving me another error... But thanks for pointing out the obvious and sending an example!
Reply With Quote Quick reply to this message  
Reply

Tags
error, transform, xml, xsl

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the XML, XSLT and XPATH Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC