Re: [xsl] xml to csv

Subject: Re: [xsl] xml to csv
From: andrew welch <andrew.j.welch@xxxxxxxxx>
Date: Mon, 21 Nov 2005 10:04:41 +0000
> I'm just wondering if it is possible to get the above output by using xslt.
> I can get solve the problem in which only one of the children of the root
> node has a subtree.
>
> 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"

I would separate this into two problems - the first is to normalize
the input tree to make sure each element contains the correct number
of children, then the second becomes very each to output the tree as
csv.

You input is a bit odd though, decide how it would look normlized and
then work from there, eg:

<root>
       <a>a</a>
       <a>a</a>
       <a>a</a>
       <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>

What would happen to the c's?  Would you get 4 <c>s, 4 <cc>s or 4
<ccc>s?  Are the <a>s correct?  It's not obvious.

Current Thread