Re: [xsl] De-flattening an XML tree

Subject: Re: [xsl] De-flattening an XML tree
From: Joerg.Heinicke@xxxxxx
Date: Wed, 9 Jan 2002 03:08:45 +0100 (MET)
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