When you think ASP, think...
Recent Articles
All Articles
ASP.NET Articles [1.x] [2.0]
ASPFAQs.com
Message Board
Related Web Technologies
User Tips!
Coding Tips
Search

Sections:
Book Reviews
Sample Chapters
Commonly Asked Message Board Questions
Headlines from ASPWire.com
JavaScript Tutorials
MSDN Communities Hub
Official Docs
Security
Stump the SQL Guru!
Web Hosts
XML
Information:
Advertise
Feedback
Author an Article
Jobs
















internet.com
IT
Developer
Internet News
Small Business
Personal Technology
International

Search internet.com
Advertise
Corporate Info
Newsletters
Tech Jobs
E-mail Offers
ASP ASP.NET ASP FAQs Message Board Feedback ASP Jobs
Print this Page!

Windows Systems Administrator
Jupitermedia
US-CT-Darien

Justtechjobs.com Post A Job | Post A Resume

Published: Wednesday, May 14, 2003

Displaying XML Data in the Internet Explorer TreeView Control, Part 2
By Scott Mitchell


  • Read Part 1

  • In Part 1 we examined how to use the TreeView Web control to not only display a static hierarchy, but also how to display a hierarchy that came from an XML data source (so long as the XML was in a proper format). In this second and final part, we'll see how to use XSLT stylesheets to convert a given XML data source into the format expected by the TreeView control.

    - continued -

    Converting a Given XML File Into the Proper Format
    XSLT, which stands for eXtensible Stylesheet Language Transform, is a technology designed to convert XML from one format to another. A thorough discussion of XSLT is beyond the scope of this article; for more information read the FAQ What is XSLT? and check out the XSL section on XMLFiles.com.

    In order to convert our initial aspnetbooks.xml to the proper XML format, we need to concoct an XSLT stylesheet. Once we have this XSLT stylesheet, we can specify in the TreeNode that it should use a stylesheet to transform the specified XML by using the TreeNodeXsltSrc property like so:

    <form runat="server">
      <ie:TreeView runat="server">
        <ie:TreeNode runat="server" Text="ASP.NET Books" Expanded="True" 
                       TreeNodeSrc="aspnetbooksTV.xml" 
                       TreeNodeXsltSrc="XSLTFile" />                  
      </ie:TreeView>
    </form>
    

    The XSLT stylesheet needed depends on the XML file's format. For the aspnetbooks.xml XML file, the following XML format will transform the XML into the format expected by the TreeView control:

    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version='1.0'>
      <xsl:template match="/books">
        <TREENODES>
          <xsl:for-each select="book">
            <treenode>
              <xsl:attribute name="text">
                <xsl:value-of select="title" />
              </xsl:attribute>
              
              <treenode>
                <xsl:attribute name="text">
                  Price - $<xsl:value-of select="@price" />
                </xsl:attribute>
              </treenode>
    
              <treenode text="Authors">
                <xsl:for-each select="authors/author">
                  <treenode>
                    <xsl:attribute name="text">
                      <xsl:value-of select="text()" />
                    </xsl:attribute>
                  </treenode>
                </xsl:for-each>
              </treenode>
    
              <treenode>
                <xsl:attribute name="text">
                  Year Published - <xsl:value-of select="year" />
                </xsl:attribute>
              </treenode>
            </treenode>
          </xsl:for-each>
        </TREENODES>
      </xsl:template>
    </xsl:stylesheet>
    

    Notice that to specify the attribute of an element in XSLT, you need to use the <xsl:attribute name="AttributeName"> tag. For example, to specify the text property of the <treenode> element, we have to use:

    <treenode>
      <xsl:attribute name="text">
        Value of text attribute
      </xsl:attribute>
      
      ...
    </treenode>
    

    With this XSLT stylesheet created and saved as aspbooks2treeview.xsl, all we need to do is specify this filename in the TreeNode's TreeNodeXsltSrc property. The following code and associated live demo shows how to use XSLT stylesheets to dynamically convert an XML document to the format required by the TreeView control.

    <form runat="server">
      <ie:TreeView runat="server">
        <ie:TreeNode runat="server" Text="ASP.NET Books" Expanded="True" 
                       TreeNodeSrc="aspnetbooksTV.xml" 
                       TreeNodeXsltSrc="aspbooks2treeview.xsl" />                  
      </ie:TreeView>
    </form>
    
    [View a Live Demo!]

    Conclusion
    In this article we examined the TreeView IE Web Control, one of the four IE Web Controls provided for free from Microsoft. This article only scratched the surface of the TreeView Web control, illustrating how to display a static hierarchy as well as a hierarchy from an XML data source.

    In addition to the capabilities we examined in this article, the TreeView Web control has a number of other functionalities. For example, images can be displayed next to each TreeNode. Also, event handlers can created so that they execute when the user clicks a TreeNode. For more information on these features, be sure to read the Internet Explorer Web Controls Reference page. Also, if you have questions on the TreeView or other IE Web Controls, consider asking them at the IE Web Controls Forum at the ASP.NET Forums.

    Happy Programming!

  • By Scott Mitchell


    Windows Internet Technology | ASP.NET [1.x] [2.0] | ASPMessageboard.com | ASPFAQs.com | Advertise | Feedback | Author an Article



  • JupiterOnlineMedia

    internet.comearthweb.comDevx.commediabistro.comGraphics.com

    Search:

    Jupitermedia Corporation has two divisions: Jupiterimages and JupiterOnlineMedia

    Jupitermedia Corporate Info


    Legal Notices, Licensing, Reprints, & Permissions, Privacy Policy.

    Advertise | Newsletters | Tech Jobs | Shopping | E-mail Offers

    Solutions
    Whitepapers and eBooks
    Microsoft Article: HyperV-The Killer Feature in WinServer ‘08
    Avaya Article: How to Feed Data into the Avaya Event Processor
    Microsoft Article: Install What You Need with Win Server ‘08
    HP eBook: Putting the Green into IT
    Whitepaper: HP Integrated Citrix XenServer for HP ProLiant Servers
    Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 1
    Intel Go Parallel Portal: Interview with C++ Guru Herb Sutter, Part 2--The Future of Concurrency
    Avaya Article: Setting Up a SIP A/S Development Environment
    IBM Article: How Cool Is Your Data Center?
    Microsoft Article: Managing Virtual Machines with Microsoft System Center
    HP eBook: Storage Networking , Part 1
    Microsoft Article: Solving Data Center Complexity with Microsoft System Center Configuration Manager 2007
    MORE WHITEPAPERS, EBOOKS, AND ARTICLES
    Webcasts
    Intel Video: Are Multi-core Processors Here to Stay?
    On-Demand Webcast: Five Virtualization Trends to Watch
    HP Video: Page Cost Calculator
    Intel Video: APIs for Parallel Programming
    HP Webcast: Storage Is Changing Fast - Be Ready or Be Left Behind
    Microsoft Silverlight Video: Creating Fading Controls with Expression Design and Expression Blend 2
    MORE WEBCASTS, PODCASTS, AND VIDEOS
    Downloads and eKits
    Sun Download: Solaris 8 Migration Assistant
    Sybase Download: SQL Anywhere Developer Edition
    Red Gate Download: SQL Backup Pro and free DBA Best Practices eBook
    Red Gate Download: SQL Compare Pro 6
    Iron Speed Designer Application Generator
    MORE DOWNLOADS, EKITS, AND FREE TRIALS
    Tutorials and Demos
    How-to-Article: Preparing for Hyper-Threading Technology and Dual Core Technology
    eTouch PDF: Conquering the Tyranny of E-Mail and Word Processors
    IBM Article: Collaborating in the High-Performance Workplace
    HP Demo: StorageWorks EVA4400
    Intel Featured Algorhythm: Intel Threading Building Blocks--The Pipeline Class
    Microsoft How-to Article: Get Going with Silverlight and Windows Live
    MORE TUTORIALS, DEMOS AND STEP-BY-STEP GUIDES