Click here to Skip to main content
12,623,744 members (34,205 online)
Click here to Skip to main content
Articles » Web Development » ASP.NET » General » Downloads

Stats

116.1K views
1.2K downloads
40 bookmarked
Posted

Transform XML using XSLT to XHTML treeview

, 15 Jan 2003
Transform XML using XSLT to XHTML treeview.
images
computer.gif
config.gif
desktop.gif
floppy.gif
folder.gif
harddrive.gif
minus.gif
MyDocuments.gif
MyImages.gif
network.gif
page.gif
plus.gif
red_ball.gif
Thumbs.db
trash.gif
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:asp="remove">

  <xsl:output method="xml" indent="yes" encoding="utf-8" omit-xml-declaration="yes"/> 
  <xsl:variable name="shift-width" select="/treeview/custom-parameters/param[@name='shift-width']/@value"/>
  <xsl:variable name="img-directory" select="/treeview/custom-parameters/param[@name='img-directory']/@value"/>
  <xsl:template match="/treeview">

  <table border="0" cellspacing="0" cellpadding="0">
      <tr><td>
      <xsl:apply-templates select="folder">
        <xsl:with-param name="depth" select="1"/>
      </xsl:apply-templates>
    </td></tr>
   </table>
        
  </xsl:template>

  <xsl:template match="folder">
    <xsl:param name="depth"/>
      <table border="0" cellspacing="0" cellpadding="0">
        <tr>
          <xsl:if test="$depth>1">
            <td width="{$shift-width}"></td>
          </xsl:if>
          <td valign="top">
            <a onclick="toggle(this)" class="folder">
            <img src="{$img-directory}plus.gif"/>
            <img src="{$img-directory}{@img}"/><xsl:value-of select="@title"/></a>
            <div>
              <xsl:attribute name="style">display:none;</xsl:attribute>
              <xsl:apply-templates select="folder">
                <xsl:with-param name="depth" select="$depth+1"/>
              </xsl:apply-templates>
              <xsl:apply-templates select="leaf"/>
            </div>
          </td>
        </tr>
      </table>
  </xsl:template>
  
  <xsl:template match="leaf">
    <table border="0" cellspacing="0" cellpadding="0">
      <tr>
      <td width="{$shift-width}"></td> 
        <td valign="top">
          <a class="leaf"><xsl:attribute name="onclick">selectLeaf('<xsl:value-of select="@title"/>','<xsl:value-of select="@url"/>')</xsl:attribute>
            <img src="{$img-directory}{@img}"/>
            <xsl:value-of select="@title"/>
          </a>
        </td>
      </tr>
      </table>
  </xsl:template>
  
</xsl:stylesheet>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

Share

About the Author

Peter Huisman
Netherlands Netherlands
No Biography provided

You may also be interested in...

Pro
Pro
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161128.1 | Last Updated 16 Jan 2003
Article Copyright 2003 by Peter Huisman
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid