This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: Flattening a XML tree
- To: "'xsl-list at lists dot mulberrytech dot com'" <xsl-list at lists dot mulberrytech dot com>
- Subject: RE: [xsl] Flattening a XML tree
- From: "Zwetselaar M. van (Marco)" <Marco dot van dot Zwetselaar at nl dot fortis dot com>
- Date: Tue, 2 Oct 2001 09:19:08 +0200
- Reply-To: xsl-list at lists dot mulberrytech dot com
Farooq wrote:
> I have an input tree that looks like this
>
> <?xml version="1.0"?>
> <Tree>
> <TreeNode id="1" weight="5">
> <TreeNode id="2" weight="3">
> <TreeNode id="6" weight="2"/>
> <TreeNode id="7" weight="2"/>
> <TreeNode id="8" weight="2"/>
> </TreeNode>
> <TreeNode id="3" weight="4">
> <TreeNode id="9" weight="3">
> <TreeNode id="11" weight="2"/>
> <TreeNode id="12" weight="2"/>
> </TreeNode>
> <TreeNode id="10" weight="2"/>
> </TreeNode>
> <TreeNode id="4" weight="2"/>
> <TreeNode id="5" weight="2"/>
> </TreeNode>
> </Tree>
>
> I need to flatten the tree to a structure that looks like this. I've
> looked at the archives, but haven't found an answer.
>
> <?xml version="1.0"?>
> <Tree>
> <TreeNode id="1" weight="5">
> <TreeNode id="2" weight="3"/>
> <TreeNode id="3" weight="4"/>
> <TreeNode id="4" weight="2"/>
> <TreeNode id="5" weight="2"/>
> <TreeNode id="6" weight="2"/>
> <TreeNode id="7" weight="2"/>
> <TreeNode id="8" weight="2"/>
> <TreeNode id="11" weight="2"/>
> <TreeNode id="12" weight="2"/>
> <TreeNode id="9" weight="3"/>
> <TreeNode id="10" weight="2"/>
> </TreeNode>
> </Tree>
Why would you expect to find an answer in the archives? It looks like any
other XSLT problem to me. And the way it usually is with problems, you need
to do some thinking to solve them.
<xsl:template match="Tree">
<xsl:copy>
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
<xsl:template match="Tree/TreeNode">
<xsl:copy>
<xsl:copy-of select="@*" />
<xsl:apply-templates />
</xsl:copy>
</xsl:template>
<xsl:template match="TreeNode">
<xsl:copy>
<xsl:copy-of select="@*" />
</xsl:copy>
<xsl:apply-templates />
</xsl:template>
Regards,
Marco
DISCLAIMER: I have no control over the following disclaimer,
my company puts it there.
***************************DISCLAIMER***********************************
Deze e-mail is uitsluitend bestemd voor de geadresseerde(n).
Verstrekking aan en gebruik door anderen is niet toegestaan.
Fortis sluit iedere aansprakelijkheid uit die voortvloeit uit
electronische verzending.
This e-mail is intended exclusively for the addressee(s), and may
not be passed on to, or made available for use by any person
other than the addressee(s).
Fortis rules out any and every liability resulting from any
electronic transmission.
************************************************************************
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list