I wonder if anyone can advise why the sort param is being ignored in this xslt? The code is always performing the 'otherwise' section regardless of the sort parameter.

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    xmlns:msxsl="urn:schemas-microsoft-com:xslt" exclude-result-prefixes="msxsl">

    <xsl:param name="sort"></xsl:param>

    <xsl:output method="xml" indent="yes"/>

    <xsl:template match="Products">
        <xsl:element name="Products">
            <xsl:choose>
                <xsl:when test="$sort='DATE'">
                    <xsl:apply-templates select="Product">
                        <xsl:sort data-type="number" order="descending" select="concat(substring(DateAdded,7,4), substring(DateAdded,4,2), substring(DateAdded,1,2))"/>
                    </xsl:apply-templates>
                </xsl:when>
                <xsl:when test="$sort='pricelow'">
                    <xsl:apply-templates select="Product">
                        <xsl:sort data-type="number" order="ascending" select="FromPrice"/>
                    </xsl:apply-templates>
                </xsl:when>
                <xsl:when test="$sort='pricehigh'">
                    <xsl:apply-templates select="Product">
                        <xsl:sort data-type="number" order="descending" select="FromPrice"/>
                    </xsl:apply-templates>
                </xsl:when>
                <xsl:when test="$sort='descaz'">
                    <xsl:apply-templates select="Product">
                        <xsl:sort data-type="text" order="ascending" select="Title"/>
                    </xsl:apply-templates>
                </xsl:when>
                <xsl:when test="$sort='descza'">
                    <xsl:apply-templates select="Product">
                        <xsl:sort data-type="text" order="descending" select="Title"/>
                    </xsl:apply-templates>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:apply-templates select="Product">
                        <xsl:sort data-type="number" order="ascending" select="FromPrice"/>
                    </xsl:apply-templates>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:element>
    </xsl:template>

    <xsl:template match="Product">
        <xsl:copy-of select="."/>
    </xsl:template>

</xsl:stylesheet>

Thanks

Hi Liveland,

In this XSLT , the value of sort param is blank or null. In used <xsl:choose> u dont have any <xsl:when> which can test for null value of $sort. So it is going to <xsl:otherwise>.

#
<xsl:param name="sort">DATE</xsl:param> use this line in place of urs, it'll enter into first <xsl:when>.

This question has already been answered. Start a new discussion instead.