Copied to clipboard

Flag this post as spam?

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


  • Kelsee Ishmael 71 posts 158 karma points
    May 05, 2011 @ 08:28
    Kelsee Ishmael
    0

    Dynamic Sort Using Variables

    I am trying to use xsl:sort in the new syntax. Does anybody know why this does not work?

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


    I would REALLY like to be able to use, the code below, but I'm not sure it is possible.

    <xsl:sort select="$eventSortBy" order="$eventSortOrder"/>

     

    I am setting the variables earlier in the xslt.

    Thanks!

  • Fuji Kusaka 2203 posts 4220 karma points
    May 05, 2011 @ 08:42
    Fuji Kusaka
    0

    Kaifish,


    Can you tell us more about what you want to order? How are you retrieving your data?

    Example

     

    <ul>
    <xsl:for-each select="$currentPage/* [@isDoc and string(umbracoNaviHide) != '1']">
    <xsl:sort select="current()/eventSort"  order="ascending" />
    <!-- Whatever needs to be Loaded -->
    </xsl:for-each>
    </ul>

     

  • Kelsee Ishmael 71 posts 158 karma points
    May 05, 2011 @ 08:54
    Kelsee Ishmael
    0

    It's fairly complex. Here is a simplistic version.

       <?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:ControlData="urn:ControlData"
      xmlns:TokenDates="urn:TokenDates"
      xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes"
      xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltDatesAndTimes Exslt.ExsltStrings ControlData TokenDates">


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

      <xsl:param name="currentPage"/>
    <xsl:variable name="parentNode" select="/macro/parentNode"/>
      <xsl:variable name="eventSortBy" select="/macro/eventSortBy"/>
      <xsl:variable name="eventSortOrder" select="/macro/eventSortOrder"/>
    <xsl:variable name="MaxItemsPerGroup" select="/macro/MaxItemsPerGroup"/>



      <xsl:template match="/">
    <xsl:for-each select="$parentNode/Event">

    <xsl:sort select="$eventSortBy" order="ascending"/>
    <xsl:if test="position()
    &lt;= $MaxItemsPerGroup">
       <xsl:value-of select="@nodeName"/>
    </xsl:if>

    </xsl:for-each>

    </xsl:template>


        
    </xsl:stylesheet>
  • Fuji Kusaka 2203 posts 4220 karma points
    May 05, 2011 @ 09:29
    Fuji Kusaka
    0

    Can you tr, and tell me what is the output....it should be Sorting by latest date created

     

      <xsl:sort select="@createDate" order="descending" />
  • Kelsee Ishmael 71 posts 158 karma points
    May 05, 2011 @ 17:49
    Kelsee Ishmael
    0

    It is - I can place the text I want to pass into the sort and it will work the way it needs to.

    Ex.

     <xsl:sort select="EventStartDate" order="descending" />

    or

     <xsl:sort select="eventCity" order="descending" />

    both of which are properties of the doctype I am pulling. I'm trying to set the sort type when I place my macro so I do not have to create different macros based on what output I am creating.

     

    I've seen forums that answer that the code below is the correct way to do this, but it isn't working for me. I'm guessing the reason is because I am using the new syntax.

    <xsl:sort select="data [@alias = 'productTitle']" order="ascending"/>

     

  • Kelsee Ishmael 71 posts 158 karma points
    May 05, 2011 @ 18:47
    Kelsee Ishmael
    0

    Might be worth noting that below works:

    <xsl:sort select="cityName" order="{$eventSortOrder}"/>

    but when attempting to put, what would logically make sense, I get an error for this:

    <xsl:sort select="{$eventSortBy}" order="{$eventSortOrder}"/>

     

    Error (though not that descriptive):

    Error in XSLT at line 149, char 15
    147:       <xsl:for-each select="$parentNode/descendant::* [@isDoc and name() = 'Event' and contains(string(./EventType),$EventType) and umbraco.library:DateGreaterThanOrEqual($EndDate, ./EventStartDate) and umbraco.library:DateGreaterThanOrEqual(./EventEndDate, $StartDate)]">
    148:      
    149: >>>   <xsl:sort select="{$eventSortBy}" order="{$eventSortOrder}"/> <<<
    150:      
    151:       <xsl:if test="position() &lt;= $MaxItemsPerGroup">_test_ <xsl:value-of select="$eventSortBy"/> - <xsl:value-of select="$eventSortOrder"/>


  • Kelsee Ishmael 71 posts 158 karma points
    May 05, 2011 @ 19:02
    Kelsee Ishmael
    1

    Here is the answer for anybody else having the issue. You have to use multiple sort lines. This really works like an if statement. Ex.

    <xsl:sort select="eventCity [$eventSortBy = 'eventCity']" order="{$eventSortOrder}" />
    <xsl:sort select="EventStartDate[$eventSortBy = 'EventStartDate']" order="{$eventSortOrder}" />

     

     

  • Ivan 139 posts 302 karma points
    Aug 12, 2011 @ 12:44
    Ivan
    0

    Thanks a lot!

    It was driving me crazy ;-)

Please Sign in or register to post replies

Write your reply to:

Draft