This is the mail archive of the
xsl-list@mulberrytech.com
mailing list .
RE: recursion
- To: "'xsl-list at mulberrytech dot com'" <xsl-list at mulberrytech dot com>
- Subject: RE: recursion
- From: Joshua Allen <joshuaa at microsoft dot com>
- Date: Wed, 11 Oct 2000 09:03:03 -0700
- Cc: "'oscar dot gonzalez at 100world dot es'" <oscar dot gonzalez at 100world dot es>
- Reply-To: xsl-list at mulberrytech dot com
(if you change your attribute names to id, idref (for parent), and name)
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:output method="xml" indent="yes" />
<xsl:template match="/*[position()=1]">
<xsl:call-template name="children" />
</xsl:template>
<xsl:template name="children">
<xsl:param name="parent" select="0" />
<xsl:param name="indent" select="0" />
<xsl:for-each select="/*[position()=1]/node()[@idref=$parent]" >
<level>
<xsl:attribute name="name"><xsl:value-of
select="@name"/></xsl:attribute>
<xsl:attribute name="indent">
<xsl:value-of select="$indent" />
</xsl:attribute>
<xsl:attribute name="type">
<xsl:value-of select="name(.)" />
</xsl:attribute>
<xsl:call-template name="children">
<xsl:with-param name="parent"><xsl:value-of
select="@id"/></xsl:with-param>
<xsl:with-param name="indent"><xsl:value-of select="$indent +
1"/></xsl:with-param>
</xsl:call-template>
</level>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
> -----Original Message-----
> From: Oscar Gonzalez [mailto:oscar.gonzalez@100world.es]
> Sent: Wednesday, October 11, 2000 3:32 AM
> To: 'xsl-list@mulberrytech.com'
> Subject: recursion
>
>
> I have an XML structure like that:
>
> <row ItemID="1" iParentID="0" szSubject="Msg1"/>
>
> <row ItemID="2" iParentID="1" szSubject="Msg2"/>
>
> <row ItemID="3" iParentID="2" szSubject="Msg3"/>
>
> <row ItemID="4" iParentID="1" szSubject="Msg4"/>
>
> <row ItemID="5" iParentID="4" szSubject="Msg4"/>
>
> And I want an XSLT transformation to get this data in a
> hierarchical tree
> like that:
>
> 1
> 2
> 3
> 4
> 5
>
> Can you help me?
>
> Thanks in advance....
>
>
> XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
>
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list