xsl-list
[Top] [All Lists]

Re: [xsl] Trouble sorting with <xsl:sort>

2006-06-15 06:19:18
you seem to use the sort element at wrong place.
i think you have to sort the entire rows, and not just the elements
within a specific row.

see below if it helps:

On 6/15/06, søren jepsen <demon3d2(_at_)hotmail(_dot_)com> wrote:


My XSL:

Look at <xsl:template match="row">...

<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
        <xsl:output method="xml" omit-xml-declaration="yes" version="1.0"
encoding="iso-8859-1" indent="no"/>
        <xsl:strip-space elements="*"/>
        <xsl:param name="sortby" select="'Kundenavn'"/>
        <xsl:param name="advisorId" select="'t178509'"/>
        <xsl:param name="departmentId" select="1"/>

        <xsl:template match="/">
                <html>
                        <head>
                                <link rel="stylesheet"
href="http://fioniaportalen/package/fioniabank/medarbejderportal/external/style/style.css"/>
                                <title>Talefod projekt</title>
                        </head>
                        <body>
                                <table width="100%" cellspacing="1" cellpadding="0" 
border="0"
style="padding:3px">
                                        <xsl:apply-templates 
select="talefod/fioniabank"/>
                                </table>
                        </body>
                </html>
        </xsl:template>

        <xsl:template match="fioniabank">
                        <xsl:apply-templates select="departments"/>
        </xsl:template>


        <xsl:template match="departments">
                <xsl:for-each select="department">
                        <a>
                        <xsl:attribute name="href">?departmentId=<xsl:value-of
select="@id"/></xsl:attribute>
                                <tr class="tr_top">
                                        <td class="tblColumnHd">
                                                <xsl:attribute name="colspan">
                                                        <xsl:value-of 
select="10"/>
                                                </xsl:attribute>
                                                <xsl:value-of select="@title"/>
                                        </td>
                                </tr>
                        </a>

                        <xsl:if test="@id = $departmentId">
                                <xsl:apply-templates select="advisor"/>
                        </xsl:if>

                        <tr>
                                <td height="10">
                                </td>
                        </tr>
                </xsl:for-each>
        </xsl:template>


        <xsl:template match="advisor">
                <a>
                        <xsl:attribute name="href">?advisorId=<xsl:value-of
select="@id"/>&departmentId=<xsl:value-of
select="../@id"/></xsl:attribute>
                        <tr class="tr_top">
                                <td class="tblColumnHd">
                                        <xsl:attribute name="colspan">
                                                <xsl:value-of select="10"/>
                                        </xsl:attribute>
                                        <xsl:value-of select="."/>
                                </td>
                        </tr>
                </a>

                <xsl:if test="@id = $advisorId">
                        <xsl:apply-templates 
select="//selectcustomers/headers"/>
<!-- xsl:apply-templates select="//selectcustomers/data/row"/>
replace the above statement by following: -->
                        <xsl:apply-templates 
select="//selectcustomers/data/row">
                                <xsl:sort select="elements/item[(_at_)field=$sortby]" 
order="ascending"/>
                        </xsl:apply-templates>


                </xsl:if>

                <tr>
                        <td height="10"/>
                </tr>
        </xsl:template>

        <xsl:template match="headers">
                <tr class="tr_top">
                        <xsl:for-each select="item">
                                        <td class="tblColumnHd"><xsl:value-of 
select="@title"/></td>
                        </xsl:for-each>
                </tr>
        </xsl:template>

        <xsl:template match="row">
                <tr class="evenrowno">
                        <xsl:for-each select="elements">
                                <xsl:sort select="item[field=$sortby]" 
order="ascending"/>
<!-- no need of sorting here, as your row contains only one element-->
                                <xsl:for-each select="item">
                                        <td><xsl:value-of select="." /></td>
                                </xsl:for-each>
                        </xsl:for-each>
                </tr>
        </xsl:template>

</xsl:stylesheet>



Kind Regards,

Jagdishwar B.

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>