Populating a treeview contol from an xml file

Discussion in 'ASP .Net Web Controls' started by Jason Shohet, Jul 21, 2003.

  1. Jason Shohet

    Jason Shohet Guest

    Hi,
    I'm trying to populate a treeview with an xml file. I have an xsl file
    associated with the xml file but the control asks for an TreeNodXsltSrc can
    anyone please tell me how to generate an XSLT file from an Xml file.

    Thanks for your help
     
    Jason Shohet, Jul 21, 2003
    #1
    1. Advertising

  2. Hi,

    appended is a snippet from a sample application, and I use it successfully.
    You simply do not need to use both, the xml-source and the xslt-source. So
    far I understand you, ypu have already done the transformation into xml?


    Best regards,
    Manfred Braun

    (Private)
    Mannheim
    Germany

    mailto:
    (Remove the anti-spam-underscore to mail me!)

    //===================================================================
    XmlDocument objDoc=new XmlDocument();
    objDoc.Load(xmlTreeNodesFilename);

    //Create XslTransform object and load stylesheet:
    XslTransform objXSL=new XslTransform();
    objXSL.Load(xslTreeNodemapperFilename );

    //StringWriter to temporarily hold result of the transformation:
    StringWriter writer = new StringWriter();

    //One can use this line for debugging, writing directly to the
    output-stream:
    //XmlTextWriter writer = new XmlTextWriter(Response.Output);

    //Apply transformation with no arguments and dump results to StringWriter.
    objXSL.Transform(objDoc.CreateNavigator(), null, writer);

    //Set TreeView's TreeNodeSrc property to get XML from StringWriter and
    bind data:
    TreeView1.TreeNodeTypeSrc = xmlDefaultNodeTypesFilename;
    TreeView1.TreeNodeSrc = writer.ToString();

    TreeView1.DataBind();

    //Close StringWriter
    writer.Close();

    //======================================================================
    " Jason Shohet" <> wrote in message
    news:...
    > Hi,
    > I'm trying to populate a treeview with an xml file. I have an xsl file
    > associated with the xml file but the control asks for an TreeNodXsltSrc

    can
    > anyone please tell me how to generate an XSLT file from an Xml file.
    >
    > Thanks for your help
    >
    >
     
    Manfred Braun, Jul 21, 2003
    #2
    1. Advertising

  3. Jason Shohet

    Jason Shohet Guest

    Manfred,
    Thanks for your help. But I have a few questions. In your code you refer to
    xmlTreeNodesFilename
    and xslTreeNodemapperFilename which I take to mean the XML and XSL files
    respectively. What does xmlDefaultNodeTypesFilename refer to.
    Below are my XML and Xsl files how would they apply to your code
    Thanks again,
    Jason Shohet


    ************************XML FILE**********************
    <?xml version="1.0" standalone="yes" ?>
    <HEPClasses xmlns="http://tempuri.org/HEPClass.xsd">
    <HEPClass>
    <CLASS_NO>101.1</CLASS_NO>
    <TITLE>Name of Class </TITLE>
    <COURSE_HRS>12</COURSE_HRS>
    <DESCRIPTION>Class Description</DESCRIPTION>
    <GROUP_NO>1</GROUP_NO>
    <GROUP_NAME>Name of Group</GROUP_NAME>
    <ACTIVE>true</ACTIVE>
    </HEPClass>


    *********************************XSL FILE ***************************
    <?xml version="1.0"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">
    <xsl:template match="/">
    <IGTree>
    <TreeProperties>
    <!--All the stuff goes here-->
    </TreeProperties>
    <Styles>
    <!--All the stuff goes here-->
    </Styles>
    <Levels/>
    <IslandLevels/>
    <Nodes>
    <xsl:apply-templates/>
    </Nodes>
    </IGTree>
    </xsl:template>

    <xsl:template match="HEPClass">
    <Node>
    <xsl:apply-templates select="CLASS_NO"/>
    <Nodes>
    <xsl:apply-templates select="TITLE"/>
    <xsl:apply-templates select="COURSE_HRS"/>
    <xsl:apply-templates select="DESCRIPTION"/>
    <xsl:apply-templates select="GROUP_NO"/>
    <xsl:apply-templates select="GROUP_NAME"/>
    <xsl:apply-templates select="ACTIVE"/>
    </Nodes>
    </Node>
    </xsl:template>

    <xsl:template match="CLASS_NO">
    <Text><xsl:value-of select="."/></Text>
    </xsl:template>
    <xsl:template match="TITLE">
    <Node>
    <Text><xsl:value-of select="."/></Text>
    </Node>
    </xsl:template>
    <xsl:template match="COURSE_HRS">
    <Node>
    <Text><xsl:value-of select="."/></Text>
    </Node>
    </xsl:template>
    <xsl:template match="DESCRIPTION">
    <Node>
    <Text><xsl:value-of select="."/></Text>
    </Node>
    </xsl:template>
    <xsl:template match="GROUP_NO">
    <Node>
    <Text><xsl:value-of select="."/></Text>
    </Node>
    </xsl:template>
    <xsl:template match="GROUP_NAME">
    <Node>
    <Text><xsl:value-of select="."/></Text>
    </Node>
    </xsl:template>
    <xsl:template match="ACTIVE">
    <Node>
    <Text><xsl:value-of select="."/></Text>
    </Node>
    </xsl:template>

    </xsl:stylesheet>
     
    Jason Shohet, Jul 22, 2003
    #3
  4. Hi Jason,

    sorry and sad to say, I am not the xml-guy... ;-)
    If you mail me, I would send you my xml and xsl file, so you could see, what
    I convert from/to. For your case, I am not sure, what you would like to see
    in the tree. You cannot have other "personal" properties, than the
    "NodeData", what I use to pass information to the client-side. My
    "DefaultNodetypes" are just simply three types of nodes, which apper into my
    tree, a open book, a clodes book and a html image. To can use them instead
    of giving each node that decoration. In my case, I always specify only these
    thrre type, while I am adding nodes. I add nodey danymically, after I start
    with that handful coming from my "StaricNodes...." file/s.

    Hope this help,
    Manfred Braun

    (Private)
    Mannheim
    Germany

    mailto:
    (Remove the anti-spam-underscore to mail me!)


    " Jason Shohet" <> wrote in message
    news:...
    > Manfred,
    > Thanks for your help. But I have a few questions. In your code you refer

    to
    > xmlTreeNodesFilename
    > and xslTreeNodemapperFilename which I take to mean the XML and XSL files
    > respectively. What does xmlDefaultNodeTypesFilename refer to.
    > Below are my XML and Xsl files how would they apply to your code
    > Thanks again,
    > Jason Shohet
    >
    >
    > ************************XML FILE**********************
    > <?xml version="1.0" standalone="yes" ?>
    > <HEPClasses xmlns="http://tempuri.org/HEPClass.xsd">
    > <HEPClass>
    > <CLASS_NO>101.1</CLASS_NO>
    > <TITLE>Name of Class </TITLE>
    > <COURSE_HRS>12</COURSE_HRS>
    > <DESCRIPTION>Class Description</DESCRIPTION>
    > <GROUP_NO>1</GROUP_NO>
    > <GROUP_NAME>Name of Group</GROUP_NAME>
    > <ACTIVE>true</ACTIVE>
    > </HEPClass>
    >
    >
    > *********************************XSL FILE ***************************
    > <?xml version="1.0"?>
    > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    > version="1.0">
    > <xsl:template match="/">
    > <IGTree>
    > <TreeProperties>
    > <!--All the stuff goes here-->
    > </TreeProperties>
    > <Styles>
    > <!--All the stuff goes here-->
    > </Styles>
    > <Levels/>
    > <IslandLevels/>
    > <Nodes>
    > <xsl:apply-templates/>
    > </Nodes>
    > </IGTree>
    > </xsl:template>
    >
    > <xsl:template match="HEPClass">
    > <Node>
    > <xsl:apply-templates select="CLASS_NO"/>
    > <Nodes>
    > <xsl:apply-templates select="TITLE"/>
    > <xsl:apply-templates select="COURSE_HRS"/>
    > <xsl:apply-templates select="DESCRIPTION"/>
    > <xsl:apply-templates select="GROUP_NO"/>
    > <xsl:apply-templates select="GROUP_NAME"/>
    > <xsl:apply-templates select="ACTIVE"/>
    > </Nodes>
    > </Node>
    > </xsl:template>
    >
    > <xsl:template match="CLASS_NO">
    > <Text><xsl:value-of select="."/></Text>
    > </xsl:template>
    > <xsl:template match="TITLE">
    > <Node>
    > <Text><xsl:value-of select="."/></Text>
    > </Node>
    > </xsl:template>
    > <xsl:template match="COURSE_HRS">
    > <Node>
    > <Text><xsl:value-of select="."/></Text>
    > </Node>
    > </xsl:template>
    > <xsl:template match="DESCRIPTION">
    > <Node>
    > <Text><xsl:value-of select="."/></Text>
    > </Node>
    > </xsl:template>
    > <xsl:template match="GROUP_NO">
    > <Node>
    > <Text><xsl:value-of select="."/></Text>
    > </Node>
    > </xsl:template>
    > <xsl:template match="GROUP_NAME">
    > <Node>
    > <Text><xsl:value-of select="."/></Text>
    > </Node>
    > </xsl:template>
    > <xsl:template match="ACTIVE">
    > <Node>
    > <Text><xsl:value-of select="."/></Text>
    > </Node>
    > </xsl:template>
    >
    > </xsl:stylesheet>
    >
    >
     
    Manfred Braun, Jul 22, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TW9lSm9l?=

    Button Contol

    =?Utf-8?B?TW9lSm9l?=, May 30, 2004, in forum: ASP .Net
    Replies:
    3
    Views:
    449
    Shaul Feldman
    May 30, 2004
  2. Jeff Gaines

    Contol Location on Webform

    Jeff Gaines, Nov 27, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    428
    Jeff Gaines
    Nov 27, 2004
  3. Dee
    Replies:
    2
    Views:
    297
  4. ad
    Replies:
    3
    Views:
    2,967
  5. pushpi

    Treeview contol in asp.net 2.0 with checkboxes

    pushpi, May 3, 2006, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    109
    Tech User
    Jul 4, 2006
Loading...

Share This Page