Re: [xsl] How to make tree menu from flat XML

Subject: Re: [xsl] How to make tree menu from flat XML
From: Radoslav Kolarov <roonex@xxxxxxxxx>
Date: Sun, 23 Jul 2006 10:26:13 -0700 (PDT)
Great!!! It works! Thanks for the help Mukul! :)

--- Mukul Gandhi <gandhi.mukul@xxxxxxxxx> wrote:

> You need to use the node-set extension function.
> 
> Something like following:
> 
> <xsl:stylesheet version="1.0"
>      
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
>       xmlns:msxsl="urn:schemas-microsoft-com:xslt">
> 
> <xsl:template match="/records">
>  <xsl:variable name="rtf">
>  <records>
>    <xsl:for-each select="record[parentkeynum = 0]">
>      <record>
>        <xsl:variable name="key1" select="keynum" />
>        <xsl:copy-of select="*" />
>        <xsl:for-each select="../record[parentkeynum
> =
> $key1]">
>          <record>
>            <xsl:variable name="key2" select="keynum"
> />
>            <xsl:copy-of select="*" />
>            <xsl:for-each
> select="../record[parentkeynum = $key2]">
>              <record>
>                <xsl:copy-of select="*" />
>              </record>
>            </xsl:for-each>
>          </record>
>        </xsl:for-each>
>      </record>
>    </xsl:for-each>
>  </records>
> </xsl:variable>
> 
> <xsl:call-template name="dve">
>   <xsl:with-param name="nodeset"
> select="msxsl:node-set($rtf)" />
> </xsl:call-template>
> 
> </xsl:template>
> 
> <xsl:template name="dve">
>  <xsl:param name="nodeset" />
>    <xsl:for-each select="$nodeset//records/record">
>      <xsl:call-template name="SubMenu">
>        <xsl:with-param
> name="strCSS">ParentIsVisible</xsl:with-param>
>      </xsl:call-template>
>    </xsl:for-each>
> </xsl:template>
> 
> The rest of the code would probably remain same..
> 
> Regards,
> Mukul
> 
> http://gandhimukul.tripod.com
> 
> On 7/23/06, Radoslav Kolarov <roonex@xxxxxxxxx>
> wrote:
> > Thanks Mukul,
> > The levels are only 3 yes. But how to use
> heirarchy
> > XML made by template. This is what I trying:
> >
> > <?xml version="1.0" ?>
> > <xsl:stylesheet version="1.0"
> >  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
> > <xsl:output method="xml" indent="yes"/>
> >
> > <xsl:template match="/records">
> >  <records>
> >    <xsl:for-each select="record[parentkeynum =
> 0]">
> >      <record>
> >        <xsl:variable name="key1" select="keynum"
> />
> >        <xsl:copy-of select="*" />
> >        <xsl:for-each
> select="../record[parentkeynum =
> > $key1]">
> >          <record>
> >            <xsl:variable name="key2"
> select="keynum"
> > />
> >            <xsl:copy-of select="*" />
> >            <xsl:for-each
> > select="../record[parentkeynum = $key2]">
> >              <record>
> >                <xsl:copy-of select="*" />
> >              </record>
> >            </xsl:for-each>
> >          </record>
> >        </xsl:for-each>
> >      </record>
> >    </xsl:for-each>
> >  </records>
> > <xsl:call-template name="dve">
> > </xsl:call-template>
> >
> > </xsl:template>
> >
> > <xsl:template name="dve" match="/">
> >  <xsl:for-each select="//records/record">
> >  <xsl:call-template name="SubMenu">
> >   <xsl:with-param name="strCSS">Parent
> > IsVisible</xsl:with-param>
> >  </xsl:call-template>
> >  </xsl:for-each>
> > </xsl:template>
> >
> > <xsl:template name="SubMenu">
> >  <xsl:param name="strCSS" />
> >
> >
> >
> >  <div class="{$strCSS}">
> >  <xsl:choose>
> >   <xsl:when test="count(record) > 0">
> >    <!-- Element has children, it can be expanded
> -->
> >    <input type="hidden" id="hidIsExpanded"
> value="0"
> > />
> >    <label id="lblExpand" class="Expander"
> > onclick="ExpanderClicked()">+</label>
> >   </xsl:when>
> >   <xsl:otherwise>
> >    <label class="Expander"></label>
> >   </xsl:otherwise>
> >  </xsl:choose>
> >
> >  <a><xsl:value-of select="keyname" /></a>
> >  <xsl:for-each select="record">
> >   <xsl:call-template name="SubMenu">
> >    <xsl:with-param
> > name="strCSS">NotVisible</xsl:with-param>
> >   </xsl:call-template>
> >  </xsl:for-each>
> >  </div>
> > </xsl:template>
> >
> > </xsl:stylesheet>
> >
> >
> >
> > and than I use this ASP
> >
> > <%@ Language=VBScript %>
> > <% option explicit %>
> > <HTML>
> > <HEAD>
> > <link type="text/css" rel="stylesheet"
> > href="alerts.css" />
> > </HEAD>
> > <BODY>
> > <b>Alerts</b>
> > <%
> >        dim xmlMenu
> >        dim xslMenu
> >
> >        'Get the source XML
> >        set xmlMenu =
> server.CreateObject("Microsoft.XMLDOM")
> >        xmlMenu.async = false
> >        xmlMenu.load server.MapPath("probe.xml")
> >
> >        'Get the XSLT to transform the XML
> >        set xslMenu =
> server.CreateObject("Microsoft.XMLDOM")
> >        xslMenu.async = false
> >        xslMenu.load server.MapPath("probe.xsl")
> >
> >        'Transform the source XML using XSLT
> >        Response.Write
> xmlMenu.transformNode(xslMenu)
> >
> >        set xmlMenu = nothing
> >        set xslMenu = nothing
> > %>
> >
> > <script language="jscript">
> > function ExpanderClicked()
> > {
> >        //Get the element that was clicked
> >        var ctlExpander = event.srcElement;
> >        var ctlSelectedEntry =
> ctlExpander.parentElement;
> >        //Get all the DIV elements that are direct
> > descendants
> >        var colChild =
> ctlSelectedEntry.children.tags("DIV");
> >        if(colChild.length > 0)
> >        {
> >                var strCSS;
> >                //Get the hidden element that
> indicates whether or
> > not entry is expanded
> >                var ctlHidden =
> 
=== message truncated ===


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

Current Thread