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

Re: De-flattening an XML tree

Subject: Re: De-flattening an XML tree
From: Joerg.Heinicke@xxxxxx
Date: Wed, 9 Jan 2002 03:08:58 +0100 (MET)
xml recordset to tree
I have a special solution for your problem:

<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>

<xsl:key name="data" match="data"
use="generate-id(preceding-sibling::record[1])"/>

<xsl:template match="recordset">
    <xsl:copy>
        <xsl:apply-templates select="record"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="record">
    <xsl:copy>
        <xsl:apply-templates select="key('data',generate-id())"/>
    </xsl:copy>
</xsl:template>

<xsl:template match="data">
    <xsl:copy/>
</xsl:template>
</xsl:stylesheet>

This should give you the hints for deflattening XML. But there are much more
generic stylesheets available in the archives.

Regards,

Joerg

> Hi,
> 
> I'm kind of stuck on ideas for how I might de-flatten a tree. It seems
> that I can't get the position of the next sibling with some property and I
> end up going around in circles with checking siblings because filter
> predicates seem to only work with one node at a time.
> 
> If I've got something like;
> 
> <recordset>
>   <record/>
>   <data/>
>   <data/>
>   <record/>
>   <data/>
>   <record/>
>   <data/>
>   <data/>
>   <data/>
> </recordset>
> 
> ie. we've got a record tag, followed by it's "children".
> 
> Is there any way of transforming this to:
> <recordset>
>   <record>
>     <data/>
>     <data/>
>   </record>
>   <record>
>     <data/>
>   </record>
>   <record>
>     <data/>
>     <data/>
>     <data/>
>   </record>
> </recordset>
> 
> 
> Any suggestions, ideas or strategies?
> 
> Thanks a lot!
> 
> -Benjamin Johnston
> s355171@xxxxxxxxxxxxxxxxx

-- 
GMX - Die Kommunikationsplattform im Internet.
http://www.gmx.net


 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.