Important Notice from AspDotNetStorefront
It is with dismay that we report that we have been forced, through the action of hackers, to shut off write-access to this forum. We are keen to leave the wealth of material available to you for research. We have opened a new forum from which our community of users can seek help, support and advice from us and from each other. To post a new question to our community, please visit: http://forums.vortx.com
Results 1 to 7 of 7

Thread: Start categories menu at second level

  1. #1
    Scott_LeWarne is offline Junior Member
    Join Date
    Mar 2008
    Posts
    14

    Default Start categories menu at second level

    Hi,
    I am new to using the built-in category browser implemented via the rev.categories package and I'm wondering if anyone can help me figure out how to do what I'm trying to do. My xsl is getting better, but far from expert.

    We find that certain types of custom reporting are easier when we put all of our categories under a single root parent category, we call it Products. The problem with doing that is that the category browser only shows that one category, Products, when collapsed and I want the users to be able to see the second level (my root) categories.

    So my question is how to modify it so that it starts at the second level, underneath Products? I still want it to function just the same as if the second level was the root and I had created those cats at the root level. Is this possible?

    Thanks
    Scott LeWarne
    NW Websouce
    scott@nw-websource.com

  2. #2
    Jao is offline Senior Member
    Join Date
    Oct 2008
    Posts
    1,132

    Default

    Well, the easiest way would be to create a Product as the root category, then map all your categories under it. Please feel free to correct me if I seem to misunderstood it...

  3. #3
    Scott_LeWarne is offline Junior Member
    Join Date
    Mar 2008
    Posts
    14

    Default

    That's what I've done.

    I have a Products category at the root and then several sub categories underneath it that I consider to be my true 'root level' categories. Products is really just there for some custom reporting that we have, it allows the user to get sales info easily for everything while selecting a single category within our reporting tool (this way they don' have to select all the root cats to get 'all products').

    What my problem is is that the categories browser menu (rev.categories.xml.config) starts at the root and so it always displays just 'Products' and I have to click into it to get it to expand. I want to make it function as if Products doesn't exist. List out the children of Products as if they were at the root and then function normally after that as I browse through categories, just don't ever display the real root of Products.

    I've messed with some of the XPath statements with the intent of just excluding Products from the nodeset that it has to work with it, but I can't seem to get that to work.

    Thanks
    Scott

  4. #4
    George the Great is offline Senior Member
    Join Date
    Nov 2006
    Location
    Cleveland, OH
    Posts
    1,792

    Default

    If I'm understanding you correctly, this is a simple enough modification. This is the Entity template from rev.categories.xml.config - just replace the 1's in the following code with the CategoryID of your Products category (red indicates line changes)
    Code:
     <xsl:template match="Entity">
    <xsl:param name="prefix"></xsl:param>
    <xsl:param name="eName" select="aspdnsf:GetMLValue(Name)" />
    
    
    <li class="tame">
    	<xsl:if test="number(ParentEntityID) &gt; 0"> <!-- don't render root categories -->
    		<xsl:value-of select="$prefix" />
    		<xsl:if test="number(ParentEntityID) != 1"> <!-- make 1 the ID of your products category -->
    			<span class="catMark">&gt;&gt;</span>*
    		</xsl:if>
    		<a href="{concat('c-',EntityID,'-',SEName,'.aspx')}">
    			<xsl:if test="EntityID = $CategoryID or descendant::Entity/EntityID = $CategoryID">
    				<xsl:attribute name="style">font-weight:bold</xsl:attribute>
    			</xsl:if>
    			<xsl:value-of select="$eName"/>
    		</a>
    	</xsl:if>
    	<xsl:if test="count(child::Entity)&gt;0 and ((EntityID = $CategoryID or descendant::Entity/EntityID = $CategoryID) or (descendant::Entity/ParentEntityID = 1) )"> <!-- make 1 the ID of your products category -->
            <ul class="tame">
                <xsl:apply-templates select="Entity">
                    <xsl:with-param name="prefix" select="concat($prefix, '**')"/>
                </xsl:apply-templates>
            </ul>
        </xsl:if>
    </li>
    </xsl:template>
    <a href="http://www.aspdotnetstorefront.com">Shopping Cart Software</a>

  5. #5
    art_r is offline Junior Member
    Join Date
    Jan 2010
    Posts
    20

    Default

    Sorry to hijack but I have used this code on our site with a slight variation in that I have included several root ID's to display multiple root categories expanded out. This is working ok but would like to add the root category names in between the sub categories. Can anyone help me with this in the code?

    So it should make a menu like :-

    Root Cat1
    -sub cat1.1
    -sub cat1.2
    Root Cat2
    -sub cat2.1
    -sub cat2.2
    Root Cat3
    -sub cat3.1
    -sub cat3.2


    Where as I am just getting :-

    -sub cat1.1
    -sub cat1.2
    -sub cat2.1
    -sub cat2.2
    -sub cat3.1
    -sub cat3.2

    thanks for any assistance.

    a.


    Code:
     <xsl:template match="Entity">
    <xsl:param name="prefix"></xsl:param>
    <xsl:param name="eName" select="aspdnsf:GetMLValue(Name)" />
    
    
    <li class="tame">
    	<xsl:if test="number(ParentEntityID) &gt; 0"> 
    		<xsl:value-of select="$prefix" />
    <xsl:if test="number(ParentEntityID) != 1"> 
    			<span class="catMark">&gt;&gt;</span>*
    		</xsl:if>
    		<a href="{concat('c-',EntityID,'-',SEName,'.aspx')}">
    			<xsl:if test="EntityID = $CategoryID or descendant::Entity/EntityID = $CategoryID">
    				<xsl:attribute name="style">font-weight:bold</xsl:attribute>
    			</xsl:if>
    			<xsl:value-of select="$eName"/>
    		</a>
    	</xsl:if>
    	<xsl:if test="count(child::Entity)&gt;0 and ((EntityID = $CategoryID or descendant::Entity/EntityID = $CategoryID) or (descendant::Entity/ParentEntityID = 1) or (descendant::Entity/ParentEntityID = 2) or (descendant::Entity/ParentEntityID = 3) )"> <!-- made ID's root of my main categories -->
            <ul class="tame">
                <xsl:apply-templates select="Entity">
                    <xsl:with-param name="prefix" select="concat($prefix, '**')"/>
                </xsl:apply-templates>
            </ul>
        </xsl:if>
    </li>
    </xsl:template>

  6. #6
    art_r is offline Junior Member
    Join Date
    Jan 2010
    Posts
    20

    Default

    Ok found that removing <xsl:if test="number(ParentEntityID) &gt; 0"> and relevant </xsl:if> shows the root again, now just need to work out how to change the class on this so it looks different to the normal list.

  7. #7
    Ajeet Kumar is offline Junior Member
    Join Date
    Aug 2010
    Location
    Noida, India
    Posts
    3

    Default It's not working

    I'v changed my code according your given article:

    I want my left navigation in this format:
    Category-1 (50)
    >> Sub-Cat1(25)
    >> Sub-Cat2(25)
    Category-2(50)
    >> Sub-Cat1(25)
    >> Sub-Cat2(25)


    & my code of rev.categories.xml.config:

    <?xml version="1.0" standalone="yes" ?>
    <!-- ################################################## ################################################## ## -->
    <!-- Copyright AspDotNetStorefront.com, 1995-2010. All Rights Reserved. -->
    <!-- http://www.aspdotnetstorefront.com -->
    <!-- For details on this license please visit the product homepage at the URL above. -->
    <!-- THE ABOVE NOTICE MUST REMAIN INTACT. -->
    <!-- ################################################## ################################################## ## -->
    <package version="2.1" displayname="Categories" debug="false" includeentityhelper="true">
    <PackageTransform>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:aspdnsf="urn:aspdnsf" exclude-result-prefixes="aspdnsf">
    <xslutput method="html" omit-xml-declaration="yes"/>

    <xslaram name="CategoryID">
    <xsl:choose>
    <xsl:when test="/root/System/PageName = 'showmanufacturer.aspx' or /root/System/PageName = 'showsection.aspx' or /root/System/PageName = 'showdistributor.aspx' or /root/System/PageName = 'showvector.aspx' or /root/System/PageName = 'showgenre.aspx'">0</xsl:when>
    <xsl:when test="/root/System/PageName = 'showcategory.aspx' and boolean(/root/QueryString/categoryid)">
    <xsl:value-of select="/root/QueryString/categoryid"/>
    </xsl:when>
    <xsl:when test="(/root/System/PageName = 'showcategory.aspx' or /root/System/PageName = 'showproduct.aspx') and boolean(/root/Cookies/LastViewedEntityInstanceID) and /root/Cookies/LastViewedEntityName = 'Category'">
    <xsl:value-of select="/root/Cookies/LastViewedEntityInstanceID"/>
    </xsl:when>
    <xsltherwise>0</xsltherwise>
    </xsl:choose>
    </xslaram>

    <xslaram name="AncestorID">
    <xsl:for-each select="/root/EntityHelpers/Category//Entity[EntityID = $CategoryID]">
    <xsl:value-of select="ancestor::*/EntityID"/>
    </xsl:for-each>
    </xslaram>

    <xslaram name="ParentID">
    <xsl:for-each select="/root/EntityHelpers/Category//Entity[EntityID = $CategoryID]">
    <xsl:value-of select="parent::*/EntityID"/>
    </xsl:for-each>
    </xslaram>


    <xsl:template match="/">
    <xsl:element name="ul">
    <xsl:attribute name="class">
    <![CDATA[tame]]>
    </xsl:attribute>

    <xsl:apply-templates select="/root/EntityHelpers/Category/Entity">
    <xsl:with-param name="prefix" select="''"/>
    </xsl:apply-templates>

    </xsl:element>
    </xsl:template>

    <xsl:template match="Entity">
    <xslaram name="prefix"></xslaram>
    <xslaram name="eName" select="aspdnsf:GetMLValue(Name)" />


    <li class="tame">
    <xsl:if test="number(ParentEntityID) &gt; 0">
    <!-- don't render root categories -->

    <xsl:value-of select="$prefix" />
    <xsl:if test="number(ParentEntityID) != 1">
    <!-- make 1 the ID of your products category -->

    <!--<xsl:if test="number(ParentEntityID) != 0">-->
    <span class="catMark">&gt;&gt;</span>&#160;
    </xsl:if>
    <a href="{concat('c-',EntityID,'-',SEName,'.aspx')}">
    <xsl:if test="EntityID = $CategoryID or descendant::Entity/EntityID = $CategoryID">
    <xsl:attribute name="style">font-weight:bold</xsl:attribute>
    </xsl:if>
    <xsl:value-of select="$eName"/>
    </a>
    </xsl:if>

    <xsl:if test="count(child::Entity)&gt;0 and ((EntityID = $CategoryID or descendant::Entity/EntityID = $CategoryID) or (descendant::Entity/ParentEntityID = 1) )">
    <!-- make 1 the ID of your products category -->

    <!--<xsl:if test="count(child::Entity)&gt;0 and (EntityID = $CategoryID or descendant::Entity/EntityID = $CategoryID)">-->
    <ul class="tame">
    <xsl:apply-templates select="Entity">
    <xsl:with-param name="prefix" select="concat($prefix, '&#160;&#0160;')"/>
    </xsl:apply-templates>
    </ul>
    </xsl:if>
    </li>
    </xsl:template>

    </xsl:stylesheet>
    </PackageTransform>
    </package>