Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Build beautiful tree using XSL

Status
Not open for further replies.

Jahbif

Programmer
Sep 18, 2001
4
0
0
FR
I use a XSL to build a tree to structure my datas.
But I want to display it Windows Explorater (with + and - to show or not sub directories).

I believed you can do that with Java Script, How
?

Thanks for help
 
I got it.How to display it Windows Explorater

I'm gona show you the example..

1.xml

<?xml version=&quot;1.0&quot;?>
<?xml-stylesheet type=&quot;text/xsl&quot; href=&quot;1.xsl&quot;?>
<BasicInfo ChptrName=&quot;Introduction&quot; Owner=&quot;yjchoi&quot; CreateDate=&quot;9/17/2001 11:24:38 AM&quot;>
<Folder Depth=&quot;10&quot; Title=&quot;HaveSubPage&quot; id=&quot;1&quot; Order=&quot;3&quot;>
<Folder Depth=&quot;20&quot; Title=&quot;NoSubPage&quot; id=&quot;4&quot; Order=&quot;3&quot;/>
<page Depth=&quot;20&quot; Title=&quot;1Page&quot; FileName=&quot;FileName&quot; FileType=&quot;FileType&quot; Order=&quot;2&quot;/>
<Folder Depth=&quot;20&quot; Title=&quot;HaveSubPage&quot; id=&quot;5&quot; Order=&quot;1&quot;>
<page Depth=&quot;30&quot; Title=&quot;2Page&quot; FileName=&quot;FileName&quot; FileType=&quot;FileType&quot; Order=&quot;3&quot;/>
<page Depth=&quot;30&quot; Title=&quot;1Page&quot; FileName=&quot;FileName&quot; FileType=&quot;FileType&quot; Order=&quot;1&quot;/>
<Folder Depth=&quot;30&quot; Title=&quot;NoSubPage&quot; id=&quot;6&quot; Order=&quot;2&quot;/></Folder></Folder>
<Folder Depth=&quot;10&quot; Title=&quot;NoSubPage&quot; id=&quot;2&quot; Order=&quot;1&quot;/>
<Folder Depth=&quot;10&quot; Title=&quot;NoSubPage&quot; id=&quot;3&quot; Order=&quot;4&quot;/>
<page Depth=&quot;10&quot; Title=&quot;4Page&quot; FileName=&quot;FileName&quot; FileType=&quot;FileType&quot; Order=&quot;2&quot;/></BasicInfo>



1.xsl

<?xml version=&quot;1.0&quot;?>
<xsl:transform xmlns:xsl=&quot; version=&quot;1.0&quot;
exclude-result-prefixes=&quot;xsl&quot;>
<xsl:eek:utput method=&quot;html&quot; indent=&quot;no&quot;/>

<!--Parameter for setting parent URL-->
<xsl:param name=&quot;vAlias&quot;/>
<xsl:template match=&quot;/&quot;>
<html>
<head>
<?SelectionLanguage XPath?>
<title>Sample</title>
<xsl:call-template name=&quot;script&quot;/>
</head>
<body>
<p style=&quot;color:'navy';&quot;>Showing contents of <xsl:value-of select=&quot;/folders/@name&quot;/>:</p>
<xsl:apply-templates/>
</body>
</html>
</xsl:template>

<xsl:template match=&quot;/BasicInfo&quot;>
<xsl:apply-templates>
<xsl:sort select=&quot;@Order&quot; data-type=&quot;text&quot; order=&quot;ascending&quot;/>
</xsl:apply-templates>
</xsl:template>
<!-- Matching all folder elements -->
<xsl:template match=&quot;//child::Folder&quot;>
<xsl:element name=&quot;img&quot;>
<xsl:attribute name=&quot;src&quot;> Space.gif </xsl:attribute>
<xsl:attribute name=&quot;width&quot;> <xsl:value-of select=&quot;@Depth&quot;/> </xsl:attribute>
<xsl:attribute name=&quot;height&quot;>10</xsl:attribute>
</xsl:element>
<xsl:element name=&quot;img&quot;>
<xsl:attribute name=&quot;src&quot;> Folder.gif </xsl:attribute>
</xsl:element>
<xsl:element name=&quot;a&quot;>
<xsl:attribute name=&quot;class&quot;>linktopic</xsl:attribute>
<xsl:attribute name=&quot;onclick&quot;>clickCategory('<xsl:value-of select=&quot;@id&quot;/>');</xsl:attribute>
<xsl:attribute name=&quot;style&quot;>cursor:hand;color:navy;</xsl:attribute>
<xsl:text> </xsl:text><xsl:value-of select=&quot;@Title&quot;/>
</xsl:element>
<br/>
<xsl:element name=&quot;div&quot;>
<xsl:attribute name=&quot;id&quot;><xsl:value-of select=&quot;@id&quot;/>_T</xsl:attribute>
<xsl:attribute name=&quot;style&quot;>display:'none';</xsl:attribute>
<xsl:apply-templates>
<xsl:sort select=&quot;@Order&quot; data-type=&quot;text&quot; order=&quot;ascending&quot;/>
</xsl:apply-templates>
</xsl:element>
</xsl:template>

<!--Matching all file elements-->
<xsl:template match=&quot;child::page&quot;>
<xsl:element name=&quot;img&quot;>
<xsl:attribute name=&quot;src&quot;> Space.gif </xsl:attribute>
<xsl:attribute name=&quot;width&quot;> <xsl:value-of select=&quot;@Depth&quot;/> </xsl:attribute>
<xsl:attribute name=&quot;height&quot;>10</xsl:attribute>
</xsl:element>
<xsl:element name=&quot;img&quot;>
<xsl:attribute name=&quot;src&quot;> page.gif </xsl:attribute>
</xsl:element>
<xsl:element name=&quot;a&quot;>
<xsl:attribute name=&quot;style&quot;>color:blue</xsl:attribute>
<xsl:attribute name=&quot;onmouseover&quot;>this.style.color='green';</xsl:attribute>
<xsl:attribute name=&quot;onmouseout&quot;>this.style.color='blue';</xsl:attribute>
<xsl:attribute name=&quot;target&quot;>_blank</xsl:attribute>
<xsl:choose>
<!--href attribute exists on Internet Shortcut and Shortcut file types -->
<xsl:when test=&quot;boolean(@FileName)&quot;>
<xsl:attribute name=&quot;href&quot;><xsl:value-of select=&quot;@FileName&quot;/></xsl:attribute>
</xsl:when>
<xsl:eek:therwise>
<xsl:attribute name=&quot;href&quot;><xsl:value-of select=&quot;$vAlias&quot;/><xsl:value-of select=&quot;parent::Folder/@Depth&quot;/>/<xsl:value-of select=&quot;.&quot;/></xsl:attribute>
</xsl:eek:therwise>
</xsl:choose>
<xsl:value-of select=&quot;@Title&quot;/>
</xsl:element>
<br/>
</xsl:template>
<xsl:template name=&quot;script&quot;>
<script language=&quot;JavaScript&quot;>
<![CDATA[
function clickCategory(CatIDStr)
{
var txtObj = document.all(CatIDStr + '_T');
if (txtObj.style.display == 'none'){
txtObj.style.display = '';
}
else{
txtObj.style.display = 'none';
}
window.event.cancelBubble=true;
}
]]>
</script>
</xsl:template>

</xsl:transform>


I think you had better to have 3 image files to test the example
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top