Hi again. Your code is supposed to display the tag cloud, not the list of filtered items. You need to create another separate macro that will display items filtered by a selected tag and place it to the same template along with the tag cloud macro that you showed above.
<asp:content ContentPlaceHolderId="MainContent" runat="server"> <h1><umbraco:Item field="heading" runat="server" /></h1> <!-- page heading / page title --> <umbraco:Macro Alias="TagResult" runat="server" /> <!-- calls the macro for the results in the tag cloud (shown below) --> </asp:content>
In your <xsl:template match="/">. Add a name property. Should look like this <xsl:template match="/" name="MyTemplateName">. Name it what ever you want.
After that, go into which XSLT file you would like to include "MyTemplateName" in.
At the top of your XSLT just above the <xsl:template match="/"> put <xsl:include href="../xslt/MyXSLTFileNameToInclude.xslt"/>
Then inside the opening and closing <xsl:template match="/"></xsl:template> tags where you want it you need to call the template by using
<xsl:call-template name=" MyTemplateName" />
Also in your second file I would comment or delete out the <xsl:param name="currentPage"/> You will run into conflicts between the params. XSLT file will think the currentPage param is in the page twice because you are including the other one.
I usually comment it out and use umbraco.library:GetXmlNodeCurrent() instead of $currentPage to minimize conflict between files.
<!--Commented out currentPage due to xsl-include conflicts with other xslt templates. Use umbraco.library:GetXmlNodeCurrent() inplace of any currentPage params--> <!--<xsl:param name="currentPage"/>-->
That is it. So your template you want the other XSLT file included into should look something like this:
<!--Commented out currentPage due to xsl-include conflicts with other xslt templates. Use umbraco.library:GetXmlNodeCurrent() inplace of any currentPage params--> <!--<xsl:param name="currentPage"/>-->
<xsl:template match="/">
<!--The name is the first templates name you gave to it in its <xsl:template match="/" name="MyTemplateName">--> <xsl:call-template name=" MyTemplateName" />
Filtering items according to the tag value
Hi Guys,
I'm new to this .....
I'm working on a product page. Each product item has a tag (tags) value on it that shows on the tag cloud.
I managed to pull of a tag cloud list now my next goal is to filter the products on screen according to their tag value
=============================== here's my code at the moment =================================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY nbsp " ">
]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:BlogLibrary="urn:BlogLibrary" xmlns:umbraco.contour="urn:umbraco.contour" xmlns:tagsLib="urn:tagsLib" xmlns:Foodstuffs.Umbraco.NewWorldKiosk.XsltExtensions="urn:Foodstuffs.Umbraco.NewWorldKiosk.XsltExtensions"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets BlogLibrary umbraco.contour tagsLib Foodstuffs.Umbraco.NewWorldKiosk.XsltExtensions ">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:template match="/">
<div class="radius-big gray-gradient-upward box-shadow-grey self-clear tag-cloud left mar-bot20">
<h2>Select Your Product Category</h2>
<ul class="list-inline">
<xsl:for-each select="tagsLib:getAllTags()/tags/tag[@group = 'ProductPromotion' and number(@nodesTagged) >= 1]">
<xsl:sort select="." order="ascending"/><li>
<a href="{umbraco.library:NiceUrl($currentPage/@id)}?filterby={.}">
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="@nodesTagged > 5">
<xsl:value-of select="string('tagweight5')" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('tagweight',@nodesTagged)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:value-of select="."/>
</a>
<xsl:text> </xsl:text></li>
</xsl:for-each>
</ul>
</div>
</xsl:template>
</xsl:stylesheet>
=============================== / here's my code at the moment =================================
I think the line in bold helps me sort out items ... its just that I don't know how to call items uder its tag value.
Can anyone please enlighten me on how to sort this out?
- Thanks in advance
Hi. Below is a sample how it can be achieved by an XSLT macro:
I hope it will help.
Hi, still doesn't work :(
Hi. I've written my snippet for query string like "?tag=..."
For you I suppose this should be changed:
to
<xsl:variablename="tag"select="umbraco.library:RequestQueryString('filterby')"/
Hi,
Sorry, I'm really totally new to this ...
This is my code at the moment ... just a few more questions ...
Should I make a new template for this? so ... its like ... current page --> new template
Should I update my bin file?
Am I missing a package?
really really need some help ...
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE xsl:stylesheet [
<!ENTITY nbsp " ">
]>
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:BlogLibrary="urn:BlogLibrary" xmlns:umbraco.contour="urn:umbraco.contour" xmlns:tagsLib="urn:tagsLib" xmlns:Foodstuffs.Umbraco.NewWorldKiosk.XsltExtensions="urn:Foodstuffs.Umbraco.NewWorldKiosk.XsltExtensions"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets BlogLibrary umbraco.contour tagsLib Foodstuffs.Umbraco.NewWorldKiosk.XsltExtensions ">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:template name="ProductPromotionTagCloud" match="ProductPromotionTagCloud">
<xsl:variable name="tag" select="umbraco.library:RequestQueryString('filterby')"/>
<div class="radius-big gray-gradient-upward box-shadow-grey self-clear tag-cloud left mar-bot20">
<h2>Select Your Product Category</h2>
<ul class="list-inline">
<xsl:for-each select="tagsLib:getAllTags()/tags/tag[@group = 'ProductPromotion' and number(@nodesTagged) >= 1]">
<xsl:sort select="." order="ascending"/>
<li>
<a href="{umbraco.library:NiceUrl($currentPage/@id)}?filterby={.}">
<xsl:attribute name="class">
<xsl:choose>
<xsl:when test="@nodesTagged > 5">
<xsl:value-of select="string('tagweight5')" />
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="concat('tagweight',@nodesTagged)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:value-of select="."/>
</a>
<xsl:text> </xsl:text>
</li>
</xsl:for-each>
</ul>
</div>
</xsl:template>
</xsl:stylesheet>
^^ that'sthe code at the moment ...
Hi again. Your code is supposed to display the tag cloud, not the list of filtered items. You need to create another separate macro that will display items filtered by a selected tag and place it to the same template along with the tag cloud macro that you showed above.
Hi,
So ... I created a template called "TagResult"
In it ... we have
<%@ Master Language="C#" MasterPageFile="~/masterpages/Base.master" AutoEventWireup="true" %>
<asp:content ContentPlaceHolderId="MainContent" runat="server">
<h1><umbraco:Item field="heading" runat="server" /></h1> <!-- page heading / page title -->
<umbraco:Macro Alias="TagResult" runat="server" /> <!-- calls the macro for the results in the tag cloud (shown below) -->
</asp:content>
in the macro ... I have ...
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:BlogLibrary="urn:BlogLibrary" xmlns:umbraco.contour="urn:umbraco.contour" xmlns:tagsLib="urn:tagsLib" xmlns:ucomponents.request="urn:ucomponents.request" xmlns:ucomponents.search="urn:ucomponents.search" xmlns:ucomponents.strings="urn:ucomponents.strings" xmlns:PS.XSLTsearch="urn:PS.XSLTsearch" xmlns:Foodstuffs.Umbraco.NewWorldKiosk.XsltExtensions="urn:Foodstuffs.Umbraco.NewWorldKiosk.XsltExtensions" xmlns:refactoredExtensions="urn:refactoredExtensions"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets BlogLibrary umbraco.contour tagsLib ucomponents.request ucomponents.search ucomponents.strings PS.XSLTsearch Foodstuffs.Umbraco.NewWorldKiosk.XsltExtensions refactoredExtensions ">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:param name="currentPage"/>
<xsl:param name="currentDate" select="umbraco.library:CurrentDate()"/>
<xsl:param name="categoryQs" select="umbraco.library:RequestQueryString('category')"/>
<xsl:param name="pageNumber">
<xsl:choose>
<xsl:when test="umbraco.library:RequestQueryString('page') <= 0 or string(umbraco.library:RequestQueryString('page')) = '' or string(umbraco.library:RequestQueryString('page')) = 'NaN'">
<xsl:text>0</xsl:text>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="umbraco.library:RequestQueryString('page')"/>
</xsl:otherwise>
</xsl:choose>
</xsl:param>
<xsl:param name="pageSize">
<xsl:choose>
<xsl:when test="string(umbraco.library:RequestQueryString('numberPerPage')) = 'All' or string(umbraco.library:RequestQueryString('numberPerPage')) = 'all'">
<xsl:value-of select="number(99999)"/>
</xsl:when>
<xsl:when test="string(umbraco.library:RequestQueryString('numberPerPage')) != ''">
<xsl:value-of select="umbraco.library:RequestQueryString('numberPerPage')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="number(98)"/>
</xsl:otherwise>
</xsl:choose>
</xsl:param>
<xsl:template match="/">
<!-- ============================================== -->
<!-- PRODUCT TEMPLATE -->
<xsl:param name="position"/>
<ul class="list-inline">
<li>
<xsl:attribute name="class">
<xsl:text>box</xsl:text>
<xsl:if test="$position > 2">
<xsl:text> brd-dash-top</xsl:text>
</xsl:if>
<xsl:if test="$position mod 2 = 0">
<xsl:text> brd-dash-left</xsl:text>
</xsl:if>
</xsl:attribute>
<!-- cupon labels -->
<strong>
<!--<xsl:choose>
<xsl:when test="string($ProductPromotion) = 'All'">
<xsl:value-of select="'All'"/>
</xsl:when>
<xsl:when test="number($ProductPromotion) > 0">
<xsl:value-of select="$numberPerPage"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="number(3)"/>
</xsl:otherwise>
</xsl:choose>-->
<xsl:if test="cleverBasketsDealCategory != 0">
<xsl:attribute name="class">
<xsl:text>abs spr-cupon clever-basket</xsl:text>
</xsl:attribute>
</xsl:if>
<xsl:if test="flyBuysCategory != 0">
<xsl:attribute name="class">
<xsl:text>abs spr-cupon fly-buys</xsl:text>
</xsl:attribute>
</xsl:if>
<xsl:if test="cuponSaverCategory != 0">
<xsl:attribute name="class">
<xsl:text>abs spr-cupon cupon-saver</xsl:text>
</xsl:attribute>
</xsl:if>
<xsl:if test="superSpecialsCategory != 0">
<xsl:attribute name="class">
<xsl:text>abs spr-cupon super-specials</xsl:text>
</xsl:attribute>
</xsl:if>
<xsl:if test="cleverBasketCuponCategory != 0">
<xsl:attribute name="class">
<xsl:text>abs spr-cupon clever-basket-cupon</xsl:text>
</xsl:attribute>
</xsl:if>
<xsl:if test="multiBuyCategory != 0">
<xsl:attribute name="class">
<xsl:text>abs spr-cupon multi-buys</xsl:text>
</xsl:attribute>
</xsl:if>
<xsl:if test="superDealsCategory != 0">
<xsl:attribute name="class">
<xsl:text>abs spr-cupon super-deals</xsl:text>
</xsl:attribute>
</xsl:if>
<xsl:value-of select="''"/>
</strong>
<!-- / cupon labels -->
<!--<xsl:if test="tags != ''">
<strong>
<xsl:attribute name="class">
<xsl:text>abs spr-cupon</xsl:text>
<xsl:choose>
<xsl:when test="not(contains(tags,','))">
<xsl:text> </xsl:text>
<xsl:value-of select="Terabyte.library:CmsFormatUrl(tags)"/>
</xsl:when>
<xsl:otherwise>
<xsl:for-each select="umbraco.library:Split(tags,',')/value">
<xsl:text> </xsl:text>
<xsl:value-of select="Terabyte.library:CmsFormatUrl(.)"/>
</xsl:for-each>
</xsl:otherwise>
</xsl:choose>
</xsl:attribute>
<xsl:value-of select="tags"/>
</strong>
</xsl:if>-->
<div class="desc abs">
<h4 class="red">
<xsl:value-of select="title"/>
</h4>
<!-- not used?
<xsl:if test="description != ''">
<p class="subtitle">
<xsl:value-of select="description"/>
</p>
</xsl:if>
-->
<p class="price">
<xsl:choose>
<xsl:when test="contains(unit, 'for')">
<xsl:value-of select="unit"/>
<xsl:value-of select="Foodstuffs.Umbraco.NewWorldKiosk.XsltExtensions:FormatPrice(price)" disable-output-escaping="yes"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="Foodstuffs.Umbraco.NewWorldKiosk.XsltExtensions:FormatPrice(price)" disable-output-escaping="yes"/>
<xsl:text> </xsl:text>
<xsl:value-of select="unit"/>
</xsl:otherwise>
</xsl:choose>
</p>
<xsl:if test="limit != ''">
<p class="clear">
<small>
<xsl:value-of select="limit"/>
</small>
</p>
</xsl:if>
</div>
<xsl:value-of select="Foodstuffs.Umbraco.NewWorldKiosk.XsltExtensions:GetProductCrop(image, importImagePath)" disable-output-escaping="yes"/>
<p class="abs expiry-date">
<small>
Expires <xsl:value-of select="umbraco.library:FormatDateTime(validEndDate, 'dd/MM/yy')"/>
</small>
</p>
</li>
</ul>
</xsl:template>
</xsl:stylesheet>
============================================= template =======================================================
How can i make the the items on my other xslt files call the template?
In your <xsl:template match="/">. Add a name property. Should look like this <xsl:template match="/" name="MyTemplateName">. Name it what ever you want.
After that, go into which XSLT file you would like to include "MyTemplateName" in.
At the top of your XSLT just above the <xsl:template match="/"> put <xsl:include href="../xslt/MyXSLTFileNameToInclude.xslt"/>
Then inside the opening and closing <xsl:template match="/"></xsl:template> tags where you want it you need to call the template by using
<xsl:call-template name=" MyTemplateName" />
Also in your second file I would comment or delete out the <xsl:param name="currentPage"/>
You will run into conflicts between the params. XSLT file will think the currentPage param is in the page twice because you are including the other one.
I usually comment it out and use umbraco.library:GetXmlNodeCurrent() instead of $currentPage to minimize conflict between files.
<!--Commented out currentPage due to xsl-include conflicts with other xslt templates.
Use umbraco.library:GetXmlNodeCurrent() inplace of any currentPage params-->
<!--<xsl:param name="currentPage"/>-->
That is it. So your template you want the other XSLT file included into should look something like this:
<xsl:stylesheet
version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:msxml="urn:schemas-microsoft-com:xslt"
xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets" xmlns:BlogLibrary="urn:BlogLibrary" xmlns:umbraco.contour="urn:umbraco.contour" xmlns:tagsLib="urn:tagsLib" xmlns:ucomponents.request="urn:ucomponents.request" xmlns:ucomponents.search="urn:ucomponents.search" xmlns:ucomponents.strings="urn:ucomponents.strings" xmlns:PS.XSLTsearch="urn:PS.XSLTsearch" xmlns:Foodstuffs.Umbraco.NewWorldKiosk.XsltExtensions="urn:Foodstuffs.Umbraco.NewWorldKiosk.XsltExtensions" xmlns:refactoredExtensions="urn:refactoredExtensions"
exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets BlogLibrary umbraco.contour tagsLib ucomponents.request ucomponents.search ucomponents.strings PS.XSLTsearch Foodstuffs.Umbraco.NewWorldKiosk.XsltExtensions refactoredExtensions ">
<xsl:output method="xml" omit-xml-declaration="yes"/>
<xsl:include href="../xslt/MyXSLTFileNameToInclude.xslt"/>
<!--Commented out currentPage due to xsl-include conflicts with other xslt templates.
Use umbraco.library:GetXmlNodeCurrent() inplace of any currentPage params-->
<!--<xsl:param name="currentPage"/>-->
<xsl:template match="/">
<!--The name is the first templates name you gave to it in its <xsl:template match="/" name="MyTemplateName">-->
<xsl:call-template name=" MyTemplateName" />
</xsl:template>
</xsl:stylesheet>
Woops maybe I mis-read. You may not have needed that.
is working on a reply...