SharePoint User Group UK

Share the knowledge!

Welcome to SharePoint User Group UK Sign in | Join | Help
in
Home Blogs Forums Photos Files Roller

Flat list to Tree form

Last post 07-08-2009, 9:29 AM by RichardHaigh. 1 replies.
Sort Posts: Previous Next
  •  06-30-2009, 11:07 AM 19611

    Flat list to Tree form

    I am trying to display a list in a tree form in SP Designer.

    Title, Parent
    Item1
    Item2, Item1
    Item3, Item1
    Item4, Item 2
    Item5, item1

    I wish to output it like the following.
    • Item1

      • Item2
        • Item4

      • Item3


      • Item5



    Could anyone explain how this can be achieved in SP Designer via a custom datafoor suggest other ways I could do this.

    Thanks in advance.
    James
    James Callaghan

    Cambridge, UK
    MOSS 2007, InfoPath, SP Designer
  •  07-08-2009, 9:29 AM 19735 in reply to 19611

    Re: Flat list to Tree form

    I have had to do something similar before, but rather than use SPD I developed a custom control, derived from treeview and accepting some properties for the SP list to use as the datasource.

    If you do not want to go this route you could look into using some custom xsl in the dataform web part like this to generate a set of nested ul elements.

    <xsl:stylesheet xmlns:x="http://www.w3.org/2001/XMLSchema" xmlns:d="http://schemas.microsoft.com/sharepoint/dsp" version="1.0" exclude-result-prefixes="xsl msxsl ddwrt" xmlns:ddwrt="http://schemas.microsoft.com/WebParts/v2/DataView/runtime" xmlns:asp="http://schemas.microsoft.com/ASPNET/20" xmlns:__designer="http://schemas.microsoft.com/WebParts/v2/DataView/designer" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:SharePoint="Microsoft.SharePoint.WebControls" xmlns:ddwrt2="urn:frontpage:internal">
        <xsl:output method="html" indent="no"/>
        <xsl:decimal-format NaN=""/>
        <xsl:param name="dvt_apos">&apos;</xsl:param>
        <xsl:variable name="dvt_1_automode">0</xsl:variable>
       
        <xsl:template match="/">
            <xsl:call-template name="dvt_1"/>
        </xsl:template>
       
        <xsl:template name="dvt_1">
            <xsl:variable name="dvt_StyleName">Tree</xsl:variable>
            <xsl:variable name="Rows" select="/dsQueryResponse/Rows/Row[@Parent='{root}']"/>
            <xsl:variable name="dvt_RowCount" select="count($Rows)" />
            <xsl:variable name="IsEmpty" select="$dvt_RowCount = 0" />
            <div class="tv">
                <xsl:call-template name="dvt_1.buildnodes">
                    <xsl:with-param name="Rows" select="$Rows"/>
                </xsl:call-template>
            </div>
        </xsl:template>
       
        <xsl:template name="dvt_1.buildnodes">
            <xsl:param name="Rows"/>
            <ul class="tvnode">
            <xsl:for-each select="$Rows">
                <li class="tvnode">
                    <span>
                        <xsl:value-of select="@Title"/>
                    </span>
                   
                    <xsl:variable name="parentid" select="concat('{',string(@ID),'}')" />
                    <xsl:variable name="ChildRows" select="/dsQueryResponse/Rows/Row[@Parent=$parentid]"/>
    <xsl:value-of select="$parentid" />
                <xsl:call-template name="dvt_1.buildnodes">
                    <xsl:with-param name="Rows" select="$ChildRows" />
                </xsl:call-template>
               
                </li>
            </xsl:for-each>
            </ul>
        </xsl:template>
           
        </xsl:stylesheet>

View as RSS news feed in XML
Powered by Community Server, by Telligent Systems