Posted on 05/11/2009 09:28:44
I have used XSLT to achieve a similar effect. (See attached file)
Explanation:
The basis of the method is, to get DW to output all products in xml, allowing me to use XSLT to select which products to display. I do this using the Ecom module, choosing the relevant product groups and selecting the maximum number of items per page (unfortunately the current max is 100, so I believe this trick only works for <100 product sites).
I control the compared products using three URL parameters (use more if you need to compare more than three products). An example URL would be www.site.com/compare.aspx?s1=prod_name_1&s2=prod_name_2&s3=prod_name_3.
The URL parameters will also be included in the output XML, so we are all set to make the XSLT template.
XSLT Template:
1.
First I save the URL parameters (products to be compared) in separate variables:
<xsl:variable name="s1"><xsl:value-of select="/Template/Server.Request.s1" /></xsl:variable>
<xsl:variable name="s2"><xsl:value-of select="/Template/Server.Request.s2" /></xsl:variable>
<xsl:variable name="s3"><xsl:value-of select="/Template/Server.Request.s3" /></xsl:variable>
2.
Next, I create named templates for each field of the product I wish to compare. I do this, because I need to style the data once for each product. For this I need to call the template with a parameter, to tell the template which product to fetch data for.
The following example calls a template that writes out the energy class of the product:
<!-- Fetch energy consumption -->
<xsl:call-template name="energyclass"><xsl:with-param name="q" select="$s1"/></xsl:call-template>
<xsl:call-template name="energyclass"><xsl:with-param name="q" select="$s2"/></xsl:call-template>
<xsl:call-template name="energyclass"><xsl:with-param name="q" select="$s3"/></xsl:call-template>
3.
Now all we need is to create the template for displaying the energy class:
<!-- Template for displaying the energyclass -->
<xsl:template name="energyclass">
<xsl:param name="q"/>
<xsl:if test="$q != ''">
<xsl:for-each select="loop[@name='Products']/item[contains(Ecom.Product.Name, $q)][1]">
<xsl:value-of select="Ecom.Product.Field.energyclass.Value" />
</xsl:for-each>
/xsl:if>
</xsl:template>
First we check if the parameter is empty. This means that we can handle cases when the user only wants to compare two products. Next I use the for-each loop to target the product I want data for. I'm selecting items form the Products loop with a product name name that contains the URL parameter. This way, even a partial query will product results. Be precise with your URL parameters, though, as the for-each loop may catch more than one product otherwise and we don't want that. Only thing left is to output the value of the field.
Step 2+3 should be repeated for every field you wish to compare. I have included an example of a simple XSLT document with this functionality.
Hope this helps :)
Btw. This forum is the worst piece of garbage I have ever seen, writing this post was a nightmare. There is no excuse for this, any Open Source alternative is superior by a large order of magnitude.