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 2 of 2

Thread: Show all sub categories under a parent category

  1. #1
    supergriff is offline Senior Member
    Join Date
    Sep 2007
    Posts
    102

    Default Show all sub categories under a parent category

    I need to create an XML package that displays all sub categories under a root category by default. Also, if one of those sub categories is selected, then any child categories for that sub category should be shown.. hope that makes sense!

    THe package below almost works, but not quite. The 'root' category is 161. If either category 161 or any descendant category is selected the navigation displays perfectly. However if the home page (no category), or any other categories that are not either 161 or a descendant are selected, nothing is displayed....

    Can anyone offer any guidance here?

    C#/VB.NET Code:
    <xsl:template match="Entity">
              <
    xsl:param name="prefix"></xsl:param>
              <
    xsl:param name="eName" select="aspdnsf:GetMLValue(Name)" />

            <!-- 
    this will work as long as already in a sub category of lighting, if not nothing is displayed-->
            <
    xsl:if test="ancestor::Entity/EntityID = 161">
                <
    tr>
                  <
    td>
                    <
    xsl:if test="count(ancestor::Entity) = 1">
                      <
    xsl:attribute name="class">cat1</xsl:attribute>
                    </
    xsl:if>
                    <
    xsl:if test="count(ancestor::Entity) > 1">
                      <
    xsl:attribute name="class">cat2</xsl:attribute>
                    </
    xsl:if>
                    <
    xsl:value-of select="$prefix/>
                    <
    a href="{concat('c-',EntityID,'-',SEName,'.aspx')}">
                      <
    xsl:if test="EntityID = $CategoryID and count(ancestor::Entity) > 1">
                        <
    xsl:attribute name="class">lnkCat2</xsl:attribute>
                      </
    xsl:if>
                      <
    xsl:if test="EntityID != $CategoryID and count(ancestor::Entity) > 1">
                        <
    xsl:attribute name="class">lnkCat1</xsl:attribute>
                      </
    xsl:if>
                      <
    xsl:if test="EntityID = $CategoryID and count(ancestor::Entity) = 1">
                        <
    xsl:attribute name="class">lnkCatSelected</xsl:attribute>
                      </
    xsl:if>
                      <
    xsl:if test="EntityID != $CategoryID and count(ancestor::Entity) = 1">
                        <
    xsl:attribute name="class">lnkCat</xsl:attribute>
                      </
    xsl:if>
                      <
    xsl:value-of select="$eName"/>
                    </
    a>
                  </
    td>
                </
    tr>
            </
    xsl:if>

           <
    xsl:if test="count(child::Entity)&gt;0 and (EntityID = $CategoryID or descendant::Entity/EntityID = $CategoryID)">
              <
    xsl:apply-templates select="Entity">
              </
    xsl:apply-templates>
            </
    xsl:if>

          </
    xsl:template

  2. #2
    supergriff is offline Senior Member
    Join Date
    Sep 2007
    Posts
    102

    Default

    I found the answer in another thread... for anyone reading this, the xml package that worked for me is:

    C#/VB.NET Code:
    <xsl:template match="Entity">
              <
    xsl:param name="prefix"></xsl:param>
              <
    xsl:param name="eName" select="aspdnsf:GetMLValue(Name)" />
              
              <
    xsl:if test="number(ParentEntityID) &gt; 0 and ancestor::Entity/EntityID = 161">
              
              <
    tr>
                  <
    td>
                    <
    xsl:if test="count(ancestor::Entity) = 1">
                      <
    xsl:attribute name="class">cat1</xsl:attribute>
                    </
    xsl:if>
                    <
    xsl:if test="count(ancestor::Entity) > 1">
                      <
    xsl:attribute name="class">cat2</xsl:attribute>
                    </
    xsl:if>
                    <
    xsl:value-of select="$prefix/>
                    <
    a href="{concat('c-',EntityID,'-',SEName,'.aspx')}">
                      <
    xsl:if test="EntityID = $CategoryID and count(ancestor::Entity) > 1">
                        <
    xsl:attribute name="class">lnkCat2</xsl:attribute>
                      </
    xsl:if>
                      <
    xsl:if test="EntityID != $CategoryID and count(ancestor::Entity) > 1">
                        <
    xsl:attribute name="class">lnkCat1</xsl:attribute>
                      </
    xsl:if>
                      <
    xsl:if test="EntityID = $CategoryID and count(ancestor::Entity) = 1">
                        <
    xsl:attribute name="class">lnkCatSelected</xsl:attribute>
                      </
    xsl:if>
                      <
    xsl:if test="EntityID != $CategoryID and count(ancestor::Entity) = 1">
                        <
    xsl:attribute name="class">lnkCat</xsl:attribute>
                      </
    xsl:if>
                      <
    xsl:value-of select="$eName"/>
                    </
    a>
                  </
    td>
                </
    tr>


            </
    xsl:if>

            <
    xsl:if test="count(child::Entity)&gt;0 and ((EntityID = $CategoryID or descendant::Entity/EntityID = $CategoryID) or (descendant::Entity/ParentEntityID = 161))">
              <
    xsl:apply-templates select="Entity">
              </
    xsl:apply-templates>
            </
    xsl:if>
          </
    xsl:template
    Last edited by supergriff; 03-15-2010 at 07:45 PM.