Example to transform xml to text file

Discussion in 'XML' started by CSUIDL PROGRAMMEr, Feb 22, 2006.

  1. 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
    CSUIDL PROGRAMMEr, Feb 22, 2006
    #1
    1. Advertising

  2. CSUIDL PROGRAMMEr wrote:
    > 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...


    --
    Joe Kesselman / Beware the fury of a patient man. -- John Dryden
    Joseph Kesselman, Feb 22, 2006
    #2
    1. Advertising

  3. CSUIDL PROGRAMMEr

    Jeff Calico Guest

    Jeff Calico, Feb 22, 2006
    #3
  4. Re: Example to transform xml to text file

    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
    CSUIDL PROGRAMMEr, Feb 22, 2006
    #4
  5. Re: Example to transform xml to text file

    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.
    Joe Kesselman, Feb 23, 2006
    #5
  6. Re: Example to transform xml to text file

    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
    }
    }'
    Andrew Schorr, Feb 23, 2006
    #6
  7. "CSUIDL PROGRAMMEr" <> wrote in message
    news:...
    > 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
    >

    Have a look at the XML-to-flat examples in
    http://servingxml.sourceforge.net/.

    Regards,
    Daniel Parker
    Daniel Parker, Feb 24, 2006
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. KathyB
    Replies:
    0
    Views:
    1,009
    KathyB
    Jun 25, 2003
  2. Replies:
    1
    Views:
    739
    Esmond Pitt
    Mar 27, 2005
  3. Duane Morin
    Replies:
    3
    Views:
    626
    Marten Gaans
    Jan 26, 2004
  4. R. P.
    Replies:
    3
    Views:
    8,240
    Joe Kesselman
    Jun 22, 2006
  5. vsoler
    Replies:
    19
    Views:
    570
    Andreas Waldenburger
    Jan 26, 2009
Loading...

Share This Page