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:
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...
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:
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.:
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="/".
Muenchian method question
I've got a filtering macro which does two things:
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?
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:
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.:
/Chriztian
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
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!
is working on a reply...