Copied to clipboard

Flag this post as spam?

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


  • Rik Hodiamont 56 posts 156 karma points
    Dec 12, 2014 @ 16:37
    Rik Hodiamont
    0

    XSLT sorting multiple field

    Hi! 

    I have a question. I have a list of newsarticles. One newsarticle can have three writers. So I have added three input fields: Surname1, Surname2 and Surname3. 

    I have made a Xslt file that display's all the articles witch as an author with a surname starting for example with the letter N. The XSLT will display the articles with the right surname starting with a letter N. 

    For example:

    Newsarticle 1

    -- Author 1: Mr. Jones
    -- Author 2: Mr. Philips
    -- Author 3: Mr. Williams.

    Newsarticle 2

    -- Author 1: Mr. Williams
    -- Author 2: Mr. Jacobs
    -- Author 3: Mr. Philips

    Newsarticle 3

    -- Author 1: Mr. Philips
    -- Author 2: Mr. Brody
    -- Author 3: Mr. Jansen

    When you select the J the following list will apear: 

    Jones - Newsarticle 1 
    Jacobs - Newsarticle 2 
    Jansen - Newsarticle 3

    I want to sort on the surnames. Is is possible to sort as follow:

    Jacobs - Newsarticle 2 
    Jansen - Newsarticle 3
    Jones - Newsarticle 1 

    I hope you can help me!

    Rik



     

     

     

     

  • Jan Skovgaard 11280 posts 23678 karma points MVP 11x admin c-trib
    Dec 12, 2014 @ 17:27
    Jan Skovgaard
    1

    Hi Rik

    Do you mind sharing your current code, which will make it easier to help you out?

    But yes in short it should be fairly easy to sort using the surname but depending on how you xslt code is structured one might need to be aware of the context.

    Bu for instance you should be able to write something like this <xsl:sort select="surname" order="ascending" data-type="text" />

    Looking forward to hearing from you.

    /Jan

  • Rik Hodiamont 56 posts 156 karma points
    Dec 12, 2014 @ 17:50
    Rik Hodiamont
    0

    Hi Jan, 

    Thanks for your quick response.  Below is the full code. Sorry for pasting it in here this way, but I don't know another way. 

    Looking forward to hear from you.

     

    Rik 

     

    <div id="auteurs_left">

     

     

     

    <xsl:for-each select="$currentPage/ancestor-or-self::* [@isDoc]/descendant-or-self::* [@isDoc and name() ='Nummer' and nummerafbeelding !='' and string(umbracoNaviHide) != '1']">

    <xsl:sort select="randomTools:GetRandom(0,count($currentPage/ancestor-or-self::* [@isDoc]/descendant-or-self::* [@isDoc and name() ='Nummer' and string(umbracoNaviHide) != '1']))" order="ascending" />

    <xsl:if test="position() =1 ">

    <a href="{umbraco.library:NiceUrl(@id)}"> 

     <xsl:if test="nummerafbeelding !=''">

    <xsl:variable name="promotieImage_url" select="umbraco.library:GetMedia(nummerafbeelding, false)/umbracoFile "/>

    <img border="0"  src="/imageGen.ashx?image={$promotieImage_url}&amp;width={$thumbWidth}&amp;height={$thumbHeight}&amp;constrain=true" alt="{@nodeName}" title="{@nodeName}" class="thumbnail" />

    </xsl:if>

     </a>

     

    </xsl:if>

    </xsl:for-each>

    </div>

     

    <div id="auteurs_right">

    <ul>

     <xsl:variable name="letter" select="umbraco.library:RequestQueryString('letter')" />

     

    <xsl:choose>

    <xsl:when test="$letter = ''">

    <xsl:for-each select="$jaargangenRoot/descendant-or-self::* [@isDoc][name()='Artikel' or name()='Dossierartikel' or name()='Weekrecensies' or name()='Week'][starts-with(artikelachternaamAuteur1, 'A') or starts-with(artikelachternaamAuteur2, 'A') or starts-with(artikelachternaamAuteur3, 'A') or starts-with(artikelachternaamAuteur4, 'A') or starts-with(artikelachternaamVertaler1, 'A') or starts-with(artikelachternaamVertaler2, 'A') or starts-with(weekachternaamAuteur, 'A')]">

    <xsl:sort select="@nodeTypeAlias" order="ascending"/>

     

     

    <a href="{umbraco.library:NiceUrl(@id)}">

    <li><div class="auteurs_right_nummer">

     

    <xsl:if test="@nodeTypeAlias='Artikel'">

    Filter&nbsp;<xsl:value-of select="umbraco.library:GetXmlNodeById(@id)//parent::* [@isDoc]/@nodeName"/>

    </xsl:if>

    <xsl:if test="@nodeTypeAlias='Dossierartikel'">

    Dossier&nbsp;

    </xsl:if>

    <xsl:if test="@nodeTypeAlias='Weekrecensies'">

    Recensie

    </xsl:if>

    <xsl:if test="@nodeTypeAlias='Week'">

    Webfilter

    </xsl:if>

     

    </div>

    <div class="auteurs_right_nummer_details">

    <span class="auteurs_right_nummer_details_titel">

    <xsl:if test="starts-with(artikelachternaamAuteur1, 'A')">

    <xsl:value-of select="artikelvoornaamAuteur1"/>&nbsp;<xsl:value-of select="artikeltussenvoegselAuteur1"/>&nbsp;<xsl:value-of select="artikelachternaamAuteur1"/>

    </xsl:if> 

    <xsl:if test="starts-with(artikelachternaamAuteur2, 'A')">

    <xsl:value-of select="artikelvoornaamAuteur2"/>&nbsp;<xsl:value-of select="artikeltussenvoegselAuteur2"/>&nbsp;<xsl:value-of select="artikelachternaamAuteur2"/>

    </xsl:if>

    <xsl:if test="starts-with(artikelachternaamAuteur3, 'A')">

    <xsl:value-of select="artikelvoornaamAuteur3"/>&nbsp;<xsl:value-of select="artikeltussenvoegselAuteur3"/>&nbsp;<xsl:value-of select="artikelachternaamAuteur3"/>

    </xsl:if>

     

    <xsl:if test="starts-with(artikelachternaamVertaler1, 'A')">

    <xsl:value-of select="artikelvoornaamVertaler1"/>&nbsp;<xsl:value-of select="artikeltussenvoegselVertaler1"/>&nbsp;<xsl:value-of select="artikelachternaamVertaler1"/>

    </xsl:if>

    <xsl:if test="starts-with(artikelachternaamVertaler2, 'A')">

    <xsl:value-of select="artikelvoornaamVertaler2"/>&nbsp;<xsl:value-of select="artikeltussenvoegselvertaler2"/>&nbsp;<xsl:value-of select="artikelachternaamVertaler2"/>

    </xsl:if>

    <xsl:if test="starts-with(weekvoornaamAuteur, 'A')">

    <xsl:value-of select="weekachterAuteur"/>&nbsp;<xsl:value-of select="weektussenvoegselAuteur"/>&nbsp;<xsl:value-of select="weekachternaamAuteur"/>

    </xsl:if>&nbsp;

    </span>

     

    <xsl:choose>

    <xsl:when test="@nodeTypeAlias ='Week'">

    <xsl:value-of select="weekTitel"/>

    </xsl:when>

    <xsl:otherwise>

    <xsl:value-of select="artikeltitel" disable-output-escaping="yes"/>

    </xsl:otherwise>

    </xsl:choose>

    </div>

    </li>

    </a>

     

     

     

    </xsl:for-each>

    </xsl:when>

    <xsl:otherwise>

    <xsl:for-each select="$jaargangenRoot/descendant-or-self::* [@isDoc][name()='Artikel' or name()='Dossierartikel' or name()='Weekrecensies' or name()='Week'][starts-with(artikelachternaamAuteur1, $letter) or starts-with(artikelachternaamAuteur2, $letter) or starts-with(artikelachternaamAuteur3, $letter) or starts-with(artikelachternaamAuteur4, $letter) or starts-with(artikelachternaamVertaler1, $letter) or starts-with(artikelachternaamVertaler2, $letter) or starts-with(weekachternaamAuteur, $letter)]">

    <xsl:sort select="@nodeTypeAlias" order="ascending"/>

     

    <a href="{umbraco.library:NiceUrl(@id)}">

    <li>

    <div class="auteurs_right_nummer">

     

    <xsl:if test="@nodeTypeAlias='Artikel'">

    Filter&nbsp;<xsl:value-of select="umbraco.library:GetXmlNodeById(@id)//parent::* [@isDoc]/@nodeName"/>

    </xsl:if>

    <xsl:if test="@nodeTypeAlias='Dossierartikel'">

    Dossier&nbsp;

    </xsl:if>

    <xsl:if test="@nodeTypeAlias='Weekrecensies'">

    Recensie

    </xsl:if>

    <xsl:if test="@nodeTypeAlias='Week'">

    Webfilter

    </xsl:if>

     

    </div>

    <div class="auteurs_right_nummer_details">

    <span class="auteurs_right_nummer_details_titel">

    <xsl:if test="starts-with(artikelachternaamAuteur1, $letter)">

    <xsl:value-of select="artikelvoornaamAuteur1"/>&nbsp;<xsl:value-of select="artikeltussenvoegselAuteur1"/>&nbsp;<xsl:value-of select="artikelachternaamAuteur1"/>

    </xsl:if> 

    <xsl:if test="starts-with(artikelachternaamAuteur2, $letter)">

    <xsl:value-of select="artikelvoornaamAuteur2"/>&nbsp;<xsl:value-of select="artikeltussenvoegselAuteur2"/>&nbsp;<xsl:value-of select="artikelachternaamAuteur2"/>

    </xsl:if>

    <xsl:if test="starts-with(artikelachternaamAuteur3, $letter)">

    <xsl:value-of select="artikelvoornaamAuteur3"/>&nbsp;<xsl:value-of select="artikeltussenvoegselAuteur3"/>&nbsp;<xsl:value-of select="artikelachternaamAuteur3"/>

    </xsl:if>

     

    <xsl:if test="starts-with(artikelachternaamVertaler1, $letter)">

    <xsl:value-of select="artikelvoornaamVertaler1"/>&nbsp;<xsl:value-of select="artikeltussenvoegselVertaler1"/>&nbsp;<xsl:value-of select="artikelachternaamVertaler1"/>

    </xsl:if>

    <xsl:if test="starts-with(artikelachternaamVertaler2, $letter)">

    <xsl:value-of select="artikelvoornaamVertaler2"/>&nbsp;<xsl:value-of select="artikeltussenvoegselvertaler2"/>&nbsp;<xsl:value-of select="artikelachternaamVertaler2"/>

    </xsl:if>

    <xsl:if test="starts-with(weekachternaamAuteur, $letter)">

    <xsl:value-of select="weekvoornaamAuteur"/>&nbsp;<xsl:value-of select="weektussenvoegselAuteur"/>&nbsp;<xsl:value-of select="weekachternaamAuteur"/>

    </xsl:if>&nbsp;

    </span>

    <xsl:choose>

    <xsl:when test="@nodeTypeAlias ='Week'">

    <xsl:value-of select="weekTitel"/>

    </xsl:when>

    <xsl:otherwise>

    <xsl:value-of select="artikeltitel" disable-output-escaping="yes"/>

    </xsl:otherwise>

    </xsl:choose>

     

     

    </div>

    </li>

    </a>

     

     

    </xsl:for-each>

    </xsl:otherwise>

    </xsl:choose>

    </ul>

    <div style="height: 30px;float: left;width: 100%;">&nbsp;</div>

    </div>

    <div id="auteurs_overview">

    <div id="auteurs_overview_az">

    <ul>

    <li><a href="?letter=A">

    <xsl:if test="umbraco.library:RequestQueryString('letter') = 'A'">

    <xsl:attribute name="class">auteurs_overview_az_active</xsl:attribute>

    </xsl:if>

    a</a></li>

    <li><a href="?letter=B"><xsl:if test="umbraco.library:RequestQueryString('letter') = 'B'">

    <xsl:attribute name="class">auteurs_overview_az_active</xsl:attribute>

    </xsl:if>b</a></li>

    <li><a href="?letter=C"><xsl:if test="umbraco.library:RequestQueryString('letter') = 'C'">

    <xsl:attribute name="class">auteurs_overview_az_active</xsl:attribute>

    </xsl:if>c</a></li>

    <li><a href="?letter=D"><xsl:if test="umbraco.library:RequestQueryString('letter') = 'D'">

    <xsl:attribute name="class">auteurs_overview_az_active</xsl:attribute>

    </xsl:if>d</a></li>

    <li><a href="?letter=E"><xsl:if test="umbraco.library:RequestQueryString('letter') = 'E'">

    <xsl:attribute name="class">auteurs_overview_az_active</xsl:attribute>

    </xsl:if>e</a></li>

    <li><a href="?letter=F"><xsl:if test="umbraco.library:RequestQueryString('letter') = 'F'">

    <xsl:attribute name="class">auteurs_overview_az_active</xsl:attribute>

    </xsl:if>f</a></li>

    <li><a href="?letter=G"><xsl:if test="umbraco.library:RequestQueryString('letter') = 'G'">

    <xsl:attribute name="class">auteurs_overview_az_active</xsl:attribute>

    </xsl:if>g</a></li>

    <li><a href="?letter=H"><xsl:if test="umbraco.library:RequestQueryString('letter') = 'H'">

    <xsl:attribute name="class">auteurs_overview_az_active</xsl:attribute>

    </xsl:if>h</a></li>

    <li><a href="?letter=I"><xsl:if test="umbraco.library:RequestQueryString('letter') = 'I'">

    <xsl:attribute name="class">auteurs_overview_az_active</xsl:attribute>

    </xsl:if>i</a></li>

    <li><a href="?letter=J"><xsl:if test="umbraco.library:RequestQueryString('letter') = 'J'">

    <xsl:attribute name="class">auteurs_overview_az_active</xsl:attribute>

    </xsl:if>j</a></li>

    <li><a href="?letter=K"><xsl:if test="umbraco.library:RequestQueryString('letter') = 'K'">

    <xsl:attribute name="class">auteurs_overview_az_active</xsl:attribute>

    </xsl:if>k</a></li>

    <li><a href="?letter=L"><xsl:if test="umbraco.library:RequestQueryString('letter') = 'L'">

    <xsl:attribute name="class">auteurs_overview_az_active</xsl:attribute>

    </xsl:if>l</a></li>

    <li><a href="?letter=M"><xsl:if test="umbraco.library:RequestQueryString('letter') = 'M'">

    <xsl:attribute name="class">auteurs_overview_az_active</xsl:attribute>

    </xsl:if>m</a></li>

    <li><a href="?letter=N"><xsl:if test="umbraco.library:RequestQueryString('letter') = 'N'">

    <xsl:attribute name="class">auteurs_overview_az_active</xsl:attribute>

    </xsl:if>n</a></li>

    <li><a href="?letter=O"><xsl:if test="umbraco.library:RequestQueryString('letter') = 'O'">

    <xsl:attribute name="class">auteurs_overview_az_active</xsl:attribute>

    </xsl:if>o</a></li>

    <li><a href="?letter=P"><xsl:if test="umbraco.library:RequestQueryString('letter') = 'P'">

    <xsl:attribute name="class">auteurs_overview_az_active</xsl:attribute>

    </xsl:if>p</a></li>

    <li><a href="?letter=Q"><xsl:if test="umbraco.library:RequestQueryString('letter') = 'Q'">

    <xsl:attribute name="class">auteurs_overview_az_active</xsl:attribute>

    </xsl:if>q</a></li>

    <li><a href="?letter=R"><xsl:if test="umbraco.library:RequestQueryString('letter') = 'R'">

    <xsl:attribute name="class">auteurs_overview_az_active</xsl:attribute>

    </xsl:if>r</a></li>

    <li><a href="?letter=S"><xsl:if test="umbraco.library:RequestQueryString('letter') = 'S'">

    <xsl:attribute name="class">auteurs_overview_az_active</xsl:attribute>

    </xsl:if>s</a></li>

    <li><a href="?letter=T"><xsl:if test="umbraco.library:RequestQueryString('letter') = 'T'">

    <xsl:attribute name="class">auteurs_overview_az_active</xsl:attribute>

    </xsl:if>t</a></li>

    <li><a href="?letter=U"><xsl:if test="umbraco.library:RequestQueryString('letter') = 'U'">

    <xsl:attribute name="class">auteurs_overview_az_active</xsl:attribute>

    </xsl:if>u</a></li>

    <li><a href="?letter=V"><xsl:if test="umbraco.library:RequestQueryString('letter') = 'V'">

    <xsl:attribute name="class">auteurs_overview_az_active</xsl:attribute>

    </xsl:if>v</a></li>

    <li><a href="?letter=W"><xsl:if test="umbraco.library:RequestQueryString('letter') = 'W'">

    <xsl:attribute name="class">auteurs_overview_az_active</xsl:attribute>

    </xsl:if>w</a></li>

    <li><a href="?letter=X"><xsl:if test="umbraco.library:RequestQueryString('letter') = 'Q'">

    <xsl:attribute name="class">auteurs_overview_az_active</xsl:attribute>

    </xsl:if>x</a></li>

    <li><a href="?letter=Y"><xsl:if test="umbraco.library:RequestQueryString('letter') = 'Y'">

    <xsl:attribute name="class">auteurs_overview_az_active</xsl:attribute>

    </xsl:if>y</a></li>

    <li><a href="?letter=Z"><xsl:if test="umbraco.library:RequestQueryString('letter') = 'Z'">

    <xsl:attribute name="class">auteurs_overview_az_active</xsl:attribute>

    </xsl:if>z</a></li>

    </ul>

    </div>

    <div id="auteurs_overview_h1">

    auteurs

    </div>

    </div>

  • Chriztian Steinmeier 2800 posts 8791 karma points MVP 8x admin c-trib
    Dec 13, 2014 @ 22:50
    Chriztian Steinmeier
    1

    Hi Rik,

    Looking at your code I would say that you should try something like this:

    Replace the existing sort (<xsl:sort select="@nodeTypeAlias" order="ascending"/>) with these three lines:

    <xsl:sort select="artikelachternaamAuteur1" order="ascending" />
    <xsl:sort select="artikelachternaamAuteur2" order="ascending" />
    <xsl:sort select="artikelachternaamAuteur3" order="ascending" />
    

    This will sort on the surnames of the authors.

    By the way, here's a chunk of code you might find useful - it should save you a good chunk of lines of duplicated code:

    <xsl:variable name="letter" select="umbraco.library:RequestQueryString('letter')" />
    <xsl:variable name="a2z" select="umbraco.library:Split('ABCDEFGHIJKLMNOPQRSTUVWXYZ', '')" />
    
    <xsl:for-each select="$a2z/value">
        <li>
            <a href="?letter={.}">
                <xsl:if test="$letter = ."><xsl:attribute name="class">auteurs_overview_az_active</xsl:attribute></xsl:if>
                <xsl:value-of select="Exslt.ExsltStrings:lowercase(.)" />
            </a>
        </li>
    </xsl:for-each>
    

    /Chriztian

  • Rik Hodiamont 56 posts 156 karma points
    Dec 14, 2014 @ 10:50
    Rik Hodiamont
    0

    Hi Chriztian, 

    Thanks for your help and your tips!

    The sorting is working better but not for 100%. For example the B, it starts as follow:

    L. Buijs
    I. Bambust
    H. Bloemen
    R. Besselink
    H. Bloemen
    A. van Buul
    M. Bakker. Then 40 records after M. Bakker are sorted the correct way,  but then after M. van Buuren there is an A. Brink. I think the r must be before the U.Is there a way to fix this?

    Kind regards,

    Rik 

     

Please Sign in or register to post replies

Write your reply to:

Draft