[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Convert XML elements with extended attributes into CSV

Subject: Convert XML elements with extended attributes into CSV
From: Xiaocun Xu <xiaocunxu@xxxxxxxxx>
Date: Fri, 25 May 2001 20:07:59 -0700 (PDT)
xml into csv
Hi,

  I have a problem trying to convert XML elements with
extended attributes into CSV format.  For example, I
have a XML with the following structure: first part
defines the necessary extended attributes, the second
part has LineItems use both fixed and extend
attributes
<RFQ>
  <RFQExtendAttrDef Domain="line_item"
Code="item_ext1" Name="item_ext1"/>
  <RFQExtendAttrDef Domain="line_item"
Code="item_ext2" Name="item_ext2"/>
  <RFQExtendAttrDef Domain="bid" Code="bid_ext1"
Name="bid_ext1"/>
  <LineItem Name="item1" Category="cat1">
    <ExtendAttr Code="item_ext2" Value="item1 ext2"/>
  </LineItem>
  <LineItem Name="item2" Category="cat1">
    <ExtendAttr Code="item_ext1" Value="item2 ext1"/>
    <ExtendAttr Code="item_ext2" Value="item2 ext2"/>
  </LineItem>
</RFQ>

The resulting CSV I need is:
Domain,Code,Name
line_item,item_ext1,item_ext1
line_item,item_ext2,item_ext2

Name,Category,item_ext1,item_ext2
item1,cat1,,item1 ext2
item2,cat1,item2 ext1,item2 ext2

I thought the best way to attack this would be:
1. build each of the two section headers into a node,
including both fixed and extended attributes.  For
LineItem, it would like:
  <LineItemHeader>
    <cell column="1">Name</cell>
    <cell column="2">Category</cell>
    <cell column="3">item_ext1</cell>
    <cell column="4">item_ext2</cell>
  </LineItemHeader>
2. for each LineItem element, process its attributes
sequentially according to the column number indicated
in the header node, such as the LineItemHeader shown
above.

So my questions are:
1. Is the above solution fesible?
2. Is there better way to do this?
3. If there is no better way to do this, how can the
first step, i.e. build the header node, be achieved?
4. Would this solution be still fesible if the
RFQExtendAttrDef elements does NOT exist? (this is a
possibility in certain cases) Building the header node
would require scan all LineItem elements for unique
attributes.

Sorry for the long winded description, hope I managed
to describe the problem clearly.  Any suggestions
would be very much appreciated.

Thanks,
Xiaocun

__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.