Example to transform xml to text file

C

CSUIDL PROGRAMMEr

Folks
I am new to XSL and XSLT. I have xml file. I want to transform it in a
text file.
IS there any way or example that i can learn and see.
thanks
 
J

Joseph Kesselman

CSUIDL said:
I am new to XSL and XSLT. I have xml file. I want to transform it in a
text file.

First you need to decide what information you want to copy out of the
XML file, in what order.

Then write an XSLT stylesheet which yields that data, using the
<xsl:eek:utput method="text"/> directive to say you want to produce bare
text rather than XML or HTML markup.

Check the web for XSLT tutorials; some of 'em must illustrate this...
 
C

CSUIDL PROGRAMMEr

ok
here is a sample of my xml file

msg>
<date>2006-02-19</date>
<time>10:52:05</time>
<sender>syed</sender>
<receiver>#IRC</receiver>
<data>kjkk</data>
</msg>

I want output to be in this form in text file

(Date:time) sender data receiver

example

(2006-02-19:10:52:05) syed kjkk #IRC

thank
 
J

Joe Kesselman

XSLT is a programming language. There are multiple ways the simple
transform you've described could be written. Which is best depends on
what you're doing.

In any case, this really is something you ought to be able to write for
yourself after reading an XSLT tutorial or two; it's not much more than
"hello world". I'm afraid I'm going to refer you to those resources;
you'll learn more from those than from my handing you the answer.
 
A

Andrew Schorr

Using xgawk from http://sourceforge.net/projects/xmlgawk, you can solve
the problem
with this script:

xgawk -lxml '
{
switch (XMLEVENT) {
case "STARTELEM":
if (XMLNAME == "msg")
delete data
name = XMLNAME
break
case "CHARDATA":
if ($1 != "")
data[name] = $0
break
case "ENDELEM":
if (XMLNAME == "msg")
printf "(%s:%s) %s %s
%s\n",data["date"],data["time"],data["sender"],data["data"],data["receiver"]
break
}
}'
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top