Copied to clipboard

Flag this post as spam?

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


  • Vincent DeCapite 64 posts 83 karma points
    Nov 10, 2010 @ 16:32
    Vincent DeCapite
    0

    XSLT Sort Problem

    Hi All,

     

    Hopefully someone can help me with this. I have a template that is pulling in data dymanically by the products people enter. The problem is, when someone adds a new product, it automatically goes to the bottom of that category instead of being sorted alphabetically. Here is the code for the template, it takes the first 200 characters, the title, and the image. One thing that I have tried already is the sort funtion in the xslt here:

    <xsl:sort select="$products"
    order="ascending"/>

    Is this right or am I missing something..Any help would be greatly appreciated.. Thanks

    I want to sort by the title:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <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:tagsLib="urn:tagsLib"
    exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets tagsLib ">


    <xsl:output method="html" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:template match="/">
    <xsl:choose>
    <xsl:when test="$currentPage/@nodeTypeAlias = 'ProductSubcategory'">
    <xsl:call-template name="products" />
    </xsl:when>
    <xsl:otherwise>
    <xsl:call-template name="categories" />
    </xsl:otherwise>
    </xsl:choose>
    </xsl:template>


    <xsl:template name="products">

    <h1><xsl:value-of select="$currentPage/@nodeName" /></h1>

    <ul class="subCategories">
    <xsl:for-each select="$currentPage/ancestor::node [@nodeTypeAlias = 'ProductCategory']/node [@nodeTypeAlias = 'ProductSubcategory']">


    <li><a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName" /></a></li>
    </xsl:for-each>
    </ul>

    <xsl:variable name="products" select="$currentPage/ancestor-or-self::root//node [@nodeTypeAlias = 'Product' and data [@alias = 'productCategory']//item [@alias = 'productCategory'] = $currentPage/@id]" />

    <table width="100%" cellpadding="0" cellspacing="0" class="products">
    <xsl:for-each select="$products">


    <tr>
    <td width="106" valign="top">
    <xsl:choose>
    <xsl:when test="data [@alias = 'productImages'] != ''">
    <img src="/umbraco/imagegen.ashx?width=80&amp;image={umbraco.library:GetMedia(data [@alias = 'productImages'], 'True')//node[data [@alias='umbracoFile'] != '']/data [@alias ='umbracoFile']}" alt="{data [@alias = 'productName']}" width="80" />
    </xsl:when>
    <xsl:otherwise>
    <!-- Default image here? -->
    </xsl:otherwise>
    </xsl:choose>
    </td>
    <td valign="top">


    <a href="{umbraco.library:Replace(umbraco.library:NiceUrl($currentPage/@id), '.aspx', concat('/', @urlName, '.aspx'))}">
    <xsl:value-of select="data [@alias = 'productName']" />
    </a><br />
    <xsl:value-of select="umbraco.library:TruncateString(umbraco.library:StripHtml(data [@alias = 'bodyText']), '200', '...')" disable-output-escaping="yes" />
    </td>
    </tr>
    </xsl:for-each>
    </table>

    </xsl:template>
    <xsl:template name="categories">
    <h1><xsl:value-of select="$currentPage/@nodeName" /></h1>
    <xsl:for-each select="$currentPage/node [@nodeTypeAlias = 'ProductSubcategory']">
    <a href="{umbraco.library:NiceUrl(@id)}"><xsl:value-of select="@nodeName" /></a><br />
    </xsl:for-each>
    </xsl:template>


    </xsl:stylesheet>


  • Jeff Grine 149 posts 189 karma points
    Nov 10, 2010 @ 17:15
    Jeff Grine
    1

    Should be something like this:

    <xsl:sort select="data [@alias = 'productTitle']" order="ascending"/>
Please Sign in or register to post replies

Write your reply to:

Draft