Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Nikolas van Etten 202 posts 162 karma points
    Jan 23, 2011 @ 03:40
    Nikolas van Etten
    0

    Muenchian method question

    I've got a filtering macro which does two things:

    • first it checks if any filter options has been set (in the querystring) and then based on whatever settings has been set, it creates a new nodeset which is passed along to another template
    • second it used the Muenchian method to group and sort results for further filtering

    My problem is that when I pass the following code:

     

    <xsl:for-each select="$products [generate-id() = generate-id(key('manufacturer', ./productManufacturer)[1])]">
        <xsl:sort select="count(key('manufacturer', ./productManufacturer))" data-type="number" order="descending"/>
        <li>
          <a href="{umbraco.library:NiceUrl($currentPage/@id)}?m={./productManufacturer}">
            <xsl:value-of select="umbraco.library:GetXmlNodeById(./productManufacturer)/@nodeName"/>
          </a>
          <xsl:text> (</xsl:text>
          <xsl:value-of select="count(key('manufacturer', ./productManufacturer))"/>
          <xsl:text>)</xsl:text>
        </li>
      </xsl:for-each>

    The grouping works fine, but the counted records does not fit with what's in $products. So basically it uses a non-filtered list instead and counts this. As if it is using $currentPage instead of $products...

     

    Any suggestions on how to solve this? 

     

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    Jan 23, 2011 @ 23:59
    Chriztian Steinmeier
    2

    Hi Nikolas,

    How are you creating the "new nodeset" ($products) you're passing along? Are you just using a select, or are you in fact using copy-of and then the node-set() function?

    The thing is; A key() can only search the tree holding the current node, and in your case the current node is a node from the $products variable, but if that was created using xsl:param or xsl:variable, the nodes still belong to the original tree, and thus the counts will be taken from that tree too.

    If you create the $products variable like this, the keys and counts should work as expected:

    <xsl:variable name="products-filter">
        <xsl:copy-of select="SELECT_PRODUCTS_HERE" />
    </xsl:variable>
    <xsl:variable name="products" select="msxml:node-set($products-filter)/*" />

    Alternatively, you should be able to just do the counting with a predicate (it seem like a simple criterion, but maybe was simplified for this post), e.g.:

    <xsl:value-of select="count($products[productManufacturer = current()/productManufacturer])" />

    /Chriztian 

  • Nikolas van Etten 202 posts 162 karma points
    Jan 24, 2011 @ 11:39
    Nikolas van Etten
    0

    Hi Chriztian,

    This is what I've got for creating the new nodeset:

        <xsl:template match="/">
          <xsl:choose>
            <xsl:when test="$manufacturer != '' and $priceGroup != ''">
              <xsl:variable name="products" select="$currentPage/descendant-or-self::* [@isDoc and string(./productPriceNOK) != '' and string(./umbracoNaviHide) != '1']"/>
                    <xsl:call-template name="filterOptions">
            <xsl:with-param name="products" select="$products"/>
              </xsl:call-template>
            </xsl:when>
            <xsl:when test="$manufacturer != ''">
              <xsl:variable name="products" select="$currentPage/descendant-or-self::* [@isDoc and string(./productPriceNOK) != '' and string(./umbracoNaviHide) != '1' and ./productManufacturer = $manufacturer]"/>
                    <xsl:call-template name="filterOptions">
            <xsl:with-param name="products" select="$products"/>
              </xsl:call-template>
            </xsl:when>
            <xsl:when test="$priceGroup != ''">
              <xsl:variable name="products" select="$currentPage/descendant-or-self::* [@isDoc and string(./productPriceNOK) != '' and string(./umbracoNaviHide) != '1']"/>
                    <xsl:call-template name="filterOptions">
            <xsl:with-param name="products" select="$products"/>
              </xsl:call-template>
            </xsl:when>
            <xsl:otherwise>
              <xsl:variable name="products" select="$currentPage/descendant-or-self::* [@isDoc and string(./productPriceNOK) != '' and string(./umbracoNaviHide) != '1']"/>
                    <xsl:call-template name="filterOptions">
            <xsl:with-param name="products" select="$products"/>
              </xsl:call-template>
            </xsl:otherwise>
          </xsl:choose>
        </xsl:template>

    The template filterOptions is then using the Muenchian method.

     

    Nik

  • Nikolas van Etten 202 posts 162 karma points
    Jan 24, 2011 @ 21:57
    Nikolas van Etten
    0

    Chriztian,

    Your solution seemed to do the trick! I just needed to move the whole variable out of the template and create the node-set before applying template match="/".

     

    Thanks!

Please Sign in or register to post replies

Write your reply to:

Draft