473,403 Members | 2,284 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Converting XML in this format

I have an XML like this.

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <Criteria>
  3. <Messages Code="SSS" Message_Text="Congrats!" /> 
  4. <Messages Code="JJJ" Message_Text="Bad Luck"/> 
  5. </Criteria>
  6.  
Can someone help me in transforming into the following
using XSL. I want to use XSL and transform this into
XML like below.

Expand|Select|Wrap|Line Numbers
  1. <Criteria>
  2. <Messages>
  3. <Message code="APF">Congrats!</Message> 
  4. <Message code="JJJ">Bad Luck!</Message>
  5. </Messages>
  6. </Criteria>
  7.  
I used the below,but am the output in in text when i run this using the browser.

Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="ISO-8859-1"?>
  2. <!-- Edited with XML Spy v2007 (http://www.altova.com) -->
  3. <xsl:stylesheet version="1.0"
  4. xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  5. <xsl:output method='xml' version='1.0' encoding='UTF-8' indent='yes'/>
  6.  
  7. <xsl:template match="/">
  8.     <Criteria>
  9.            <Messages>
  10.             <xsl:apply-templates/>
  11.         </Messages>
  12.         </Criteria>
  13. </xsl:template>
  14.  
  15. <xsl:template match="Messages">
  16.               <Message code="{@Code}"><xsl:value-of select="@Message_Text"/></Message>
  17. </xsl:template>
  18.  
  19. </xsl:stylesheet>
  20.  
  21.  
Apr 13 '07 #1
3 1385
dorinbogdan
839 Expert 512MB
Welcome to TheScripts TSDN....

Try to update XSL this way:
[html]<xsl:template match="Messages">
&lt;Message code=&quot;<xsl:value-of select="@Code"/>&quot;&gt;<xsl:value-of select="@Message_Text"/>&lt;/Message&gt;
</xsl:template>
[/html]
Apr 13 '07 #2
Hi,
Thanks a lot for your reply.
I am using the below as mentioned :

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?xml version="1.0" encoding="ISO-8859-1"?>
  3. <!-- Edited with XML Spy v2007 (http://www.altova.com) -->
  4. <xsl:stylesheet version="1.0"
  5. xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  6. <xsl:output method='xml' version='1.0' encoding='UTF-8' indent='yes'/>
  7.  
  8. <xsl:template match="/">
  9.     <Criteria>
  10.         <Messages>
  11.             <xsl:apply-templates/>
  12.         </Messages>
  13.      </Criteria>
  14. </xsl:template>
  15.  
  16. <xsl:template match="Messages">
  17.               &lt;Message code=&quot;<xsl:value-of select="@Code"/>&quot;&gt;<xsl:value-of select="@Message_Text"/>&lt;/Message&gt;
  18. </xsl:template>
  19.  
  20. </xsl:stylesheet>
  21.  
  22.  
  23.  
And the Output now shows (in IE) as

Expand|Select|Wrap|Line Numbers
  1. <Message code="SSS">Congrats!</Message> <Message code="JJJ">Bad Luck</Message> 
  2.  
I would also like to have Criteria as the Root Element.

Help really appreciated.I am quite new to XSLT.
Apr 13 '07 #3
dorinbogdan
839 Expert 512MB
Expand|Select|Wrap|Line Numbers
  1. ....
  2. <xsl:template match="/">
  3.     &lt;Criteria&gt;
  4.         &lt;Messages&gt;
  5.             <xsl:apply-templates/>
  6.         &lt;/Messages&gt;
  7.     &lt;/Criteria&gt;
  8. </xsl:template>
  9. .......
  10.  
Apr 13 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Jonny Au | last post by:
Hi everyone, I have a problem about email message format converting. I want to write a program in VB.NET to convert the EML format email message to MSG format, does anyone knows how to do it?...
4
by: (Pete Cresswell) | last post by:
I've got everything in 2000 format right now, but it's now clear that all of the clients will be running 2003. Is there any advantage in converting? -- PeteCresswell
8
by: iyuen | last post by:
I'm having problems with converting a byte array to an image object~ My byte array is an picture in VB6 StdPicture format. I've used propertybag to convert the picture into base64Array format in...
1
by: Jonny Au | last post by:
Hi everyone, I have a problem about email message format converting. I want to write a program in VB.NET to convert the EML format email message to MSG format, does anyone knows how to do it?...
3
by: Sharon | last post by:
I have a buffer of byte that contains a raw data of a 1 byte-per-pixel image data. I need to convert this buffer to a Bitmap of Format32bppArgb and to a Bitmap of Format24bppRgb. Can anybody...
2
by: savigliano | last post by:
hello, i am doing a date comparation and i have reallize that the data i have in my database (general date format) it is causing me problems, and because i don´t need the time data i would like to...
5
by: c_shah | last post by:
I have a string in this format 100106 what is the most efficient way to convert it to a date like 10/01/2006 thanks.
2
by: Brian Parker | last post by:
I am beginning to work with VB2005.NET and I'm getting some problems with string formatting converting an application from VB6. VB6 code:- sTradeDate = Format(pArray(4,i Record), "mmddyy") ...
3
by: Jef Driesen | last post by:
How can I convert a date string to a number (e.g. a time_t value or a tm struct)? I know about the strptime function, but then I have to know the format string. And that is a problem. I'm trying...
1
by: ganesh22 | last post by:
Hi, Iam getting the below error while my application is running on IIS. in my application iam converting a text into word format, so i added some .dll from COM for converting word format ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.