XML to CSV

Discussion in 'XML' started by Serena, Nov 22, 2005.

  1. Serena

    Serena Guest

    Hi,

    I'm just wondering if it is possible to get the output below by using
    xslt. I can get solve the problem in which only one of the children of
    the root node has a subtree (i.e only <b> has children) but not the
    case where <c> and <d> have children as well.

    Any advice will be greatly appreciated.

    Thanks.

    Input:

    <?xml version="1.0" encoding="UTF-8"?>
    <root>
    <a>a</a>
    <b>
    <bb>bb1</bb>
    <bb>bb2</bb>
    <bb>bb3</bb>
    <bb>bb4</bb>
    </b>
    <c>
    <cc>
    <ccc>ccc1</ccc>
    </cc>
    <cc>
    <ccc>ccc2</ccc>
    </cc>
    </c>
    <d>
    <dd>dd1</dd>
    <dd>dd2</dd>
    </d>
    </root>

    Output:

    "a", "bb1", "ccc1", "dd1"
    "a", "bb2", "ccc1", "dd1"
    "a", "bb3", "ccc1", "dd1"
    "a", "bb4", "ccc1", "dd1"
    "a", "bb1", "ccc2", "dd1"
    "a", "bb2", "ccc2", "dd1"
    "a", "bb3", "ccc2", "dd1"
    "a", "bb4", "ccc2", "dd1"
    "a", "bb1", "ccc1", "dd2"
    "a", "bb2", "ccc1", "dd2"
    "a", "bb3", "ccc1", "dd2"
    "a", "bb4", "ccc1", "dd2"
    "a", "bb1", "ccc2", "dd2"
    "a", "bb2", "ccc2", "dd2"
    "a", "bb3", "ccc2", "dd2"
    "a", "bb4", "ccc2", "dd2"
     
    Serena, Nov 22, 2005
    #1
    1. Advertising

  2. Serena

    William Park Guest

    Serena <> wrote:
    > Hi,
    >
    > I'm just wondering if it is possible to get the output below by using
    > xslt. I can get solve the problem in which only one of the children of
    > the root node has a subtree (i.e only <b> has children) but not the
    > case where <c> and <d> have children as well.
    >
    > Any advice will be greatly appreciated.
    >
    > Thanks.
    >
    > Input:
    >
    > <?xml version="1.0" encoding="UTF-8"?>
    > <root>
    > <a>a</a>
    > <b>
    > <bb>bb1</bb>
    > <bb>bb2</bb>
    > <bb>bb3</bb>
    > <bb>bb4</bb>
    > </b>
    > <c>
    > <cc>
    > <ccc>ccc1</ccc>
    > </cc>
    > <cc>
    > <ccc>ccc2</ccc>
    > </cc>
    > </c>
    > <d>
    > <dd>dd1</dd>
    > <dd>dd2</dd>
    > </d>
    > </root>
    >
    > Output:
    >
    > "a", "bb1", "ccc1", "dd1"
    > "a", "bb2", "ccc1", "dd1"
    > "a", "bb3", "ccc1", "dd1"
    > "a", "bb4", "ccc1", "dd1"
    > "a", "bb1", "ccc2", "dd1"
    > "a", "bb2", "ccc2", "dd1"
    > "a", "bb3", "ccc2", "dd1"
    > "a", "bb4", "ccc2", "dd1"
    > "a", "bb1", "ccc1", "dd2"
    > "a", "bb2", "ccc1", "dd2"
    > "a", "bb3", "ccc1", "dd2"
    > "a", "bb4", "ccc1", "dd2"
    > "a", "bb1", "ccc2", "dd2"
    > "a", "bb2", "ccc2", "dd2"
    > "a", "bb3", "ccc2", "dd2"
    > "a", "bb4", "ccc2", "dd2"


    You are doing every permutation of a, b, c, and d elements. In shell, I
    would first store all the elements in arrays, like
    a=( a )
    b=( bb1 bb2 bb3 bb4 )
    c=( ccc1 ccc2 )
    d=( dd1 dd2 )
    and then do "cross-product". Of course, the point of your homework is
    how to extract those elements. :)

    --
    William Park <>, Toronto, Canada
    ThinFlash: Linux thin-client on USB key (flash) drive
    http://home.eol.ca/~parkw/thinflash.html
    BashDiff: Super Bash shell
    http://freshmeat.net/projects/bashdiff/
     
    William Park, Nov 22, 2005
    #2
    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. Michal Mikolajczyk
    Replies:
    0
    Views:
    662
    Michal Mikolajczyk
    Feb 13, 2004
  2. Skip Montanaro
    Replies:
    0
    Views:
    724
    Skip Montanaro
    Feb 13, 2004
  3. Tintin92
    Replies:
    1
    Views:
    1,720
    Andrew Thompson
    Feb 14, 2007
  4. jliu66
    Replies:
    0
    Views:
    518
    jliu66
    Oct 19, 2007
  5. sso
    Replies:
    20
    Views:
    2,678
    Martin Gregorie
    Apr 26, 2009
Loading...

Share This Page