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

RE: Generic stylesheet to flatten XML hierarchy

Subject: RE: Generic stylesheet to flatten XML hierarchy
From: Sara Mitchell <samitchell6@xxxxxxxxx>
Date: Fri, 4 Dec 2009 11:37:28 -0800 (PST)
RE:  Generic stylesheet to flatten XML hierarchy
Sorry, I hit Send too quickly. 

With input like this: 
<rss ...some
  <channel ...some attributes>
   <title>value may be
   ...more siblings that do not repeate
    <description> mixed content</description>
    ...more descendants
  <item> ...</item>
...more items

I would like XML output like this:
  ...more rss/@* as elements
  ...more channel/@*
<channel-title>value or perhaps CDATA surrounding mixed
  ... all other
non-repeating siblings in order as elements
  <item-title>value for first
  <item-description> probably CDATA around mixed
  ...all other item fields in order traversing
<row>...again rss attributes, channel attributes,
non-repeating children of channel followed by fields for second item </row>
...more rows ...

This example is for a single level of repeating
descendants, but my solution has to be able to handle any level of repeating
descendants. More over, the stylesheet has no knowledge of the structure of
the input document. 

I have a solution that works ok by traversing the input
document in doc order -- but it does not handle the siblings of repeating
nodes that are not themselves repeating. 

I have thought of doing this the
opposite way, get a key of all repeating nodes and process only those at the
lowest depth to generate rows.  I haven't actually written the logic. 

better ideas would be welcome.
--- On Thu, 12/3/09, Michael Kay
<mike@xxxxxxxxxxxx> wrote:

> From: Michael Kay <mike@xxxxxxxxxxxx>
> Subject:
RE:  Generic stylesheet to flatten XML hierarchy
> To:
> Date: Thursday, December 3, 2009, 3:54 PM
> I've been wandering through the
> archives and other searches 
> > and so
far have not found exactly what I am hoping to
> find. I 
> > need to write an
XSLT stylesheet that accepts an
> unknown XML 
> > document and flattens the
hierarchy to a
> two-dimensional 
> > row/columns structure. 
> > 
> The
hard part of the problem is specifying what you want to
> happen. Once
you've done that, I would think that coding it is fairly
> easy.
> Regards,
> Michael Kay
> http://www.saxonica.com/
> http://twitter.com/michaelhkay
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
> To
unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
> or e-mail:
> --~--

Current Thread


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.
First Name
Last Name
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.