Jump to content

Converting xml doc to new xml doc


MyronCope
 Share

Recommended Posts

Hi,i'm trying to convert one xml doc to a new xml doc using xml style sheet (.xsl) and I'm calling the xsl from my vb.net code but getting the following runtime exception:<code>xml readfailed.xml.xmlexception: 'xsl' is an undeclared namespace, line 2...</code>the xsl code follows:<code><?xml version="1.0" encoding="UTF-8" ?><xsl:stylesheet version="1.0" xmlns="http://www.w3.org/1999/XSL/Transform"> <xsl:template match="/expireDate"> <doi_batch></doi_batch> </xsl:template></stylesheet></code>In my new xml file I want to replace "expireDate" element with "doi_batch" but since I have not done this before it's apparent that my syntax is off. To be clear: I"m not trying to display anything, just want to convert one xml document to another and change many of the element names and much of the content.Thanks in advance for the help.

Link to comment
Share on other sites

I think I could help you but I need to know 2 things:1. Is expireDate the root node of the XML file?2. Is that the only thing you want to replace in the final output?

Link to comment
Share on other sites

I think I could help you but I need to know 2 things:1. Is expireDate the root node of the XML file?2. Is that the only thing you want to replace in the final output?

Thanks for your fast response.Answers to your questions:1. No. the root node of the original is: <asset>2. No. I would like to replace pretty much all of the fields. the new xml document structure and content is much different from the original but the new one does derive fields from the original. The new xml document that I have to create is much more complex and can go up to 7 nodes deep at times. The original goes a max 3 nodes deep. (general idea):Original.xml<code> <?xml version.....> <asset id="99999"> <coreData> <expireDate> <![CDATA[]]> </expireDate> <deployPath> <![CDATA[folder/magazine/magname/vol22/1001102.asp]]> <deployPath> . . . </coreData> <metaData> //same idea as above </metaData> <content> //again, same general idea as coreData </content> </asset></code>I need to transform the original xml file into something that looks like the following:<code> <?xml.....><doi_batch....> <head> <id>8900900</id> ..... ..... </head> <body> <Magazine> <mag_metadata language="en"> <title>Magazine Name</title> ..... </mag_metadata> <journal_issue> <Year>2001</year> <issue>22</issue> </journal_issue> .... </Magazine> </body></doi_batch></code>Thanks in advance.
Link to comment
Share on other sites

Think I figured it out:1. (dont know if this was related or not)I needed </xsl:stylesheet> near end of xsl (was missing "xsl")2. Needed this line near top of xsl:<code><xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:xs="http://www.w3.org/2001/XMLSchema"><code>Looking better now but might have follow-up questions...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...