Copied to clipboard

Flag this post as spam?

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


  • Ivan 139 posts 302 karma points
    Sep 04, 2011 @ 16:46
    Ivan
    0

    Need help to sort a list by "Embedded Content" datatype

    Hi.

    I have the following scenario of recurring events:

    Event 1

      ProgrammedDates (Embedded Content)

          Date 1 (Date picker)

          Date 2 (Date picker)

          ...

    Event 2

      ProgrammedDates (Embedded Content)

         Date 1 (Date picker)

         Date 2 (Date picker)

         ...

    To store programmed dates for each event i am using a "Embedded Content" datatype field called "ProgrammedDates" which basically stores date picker datatype fields.

    What i have to do is to show a list of next 5 upcoming events ordered by closest celebration date but i don't know how could i get it to work. I would be able to get the closest date of each event and then sort the list using this value.

    Any ideas?

    Thanks in advance for your help!!
    Ivan

  • Ivan 139 posts 302 karma points
    Sep 06, 2011 @ 19:47
    Ivan
    0

    Finally resolved it by myself. Here is the solution:

     

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


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

    <xsl:param name="currentPage"/>
        
    <xsl:variable name="resultsPerPage" select="string(PS.XSLTsearch:getParameter(string(/macro/resultsPerPage), '5'))"/>      

    <xsl:template match="/">

            <!-- Root Node -->
            <xsl:variable name="rootNode" select="$currentPage/ancestor-or-self::root" />
            <!-- Homepage -->
            <xsl:variable name="homeNode" select="$currentPage/ancestor-or-self::JWeb_Home [@isDoc]" />

            <xsl:variable name="matchedNodes" select="$homeNode/descendant-or-self::* [@isDoc and local-name()='Tour' and string(umbracoNaviHide) != '1']"/>
      
            <xsl:variable name="tmpTourItems">
              <tourslist>
                <xsl:for-each select="$homeNode/descendant-or-self::* [@isDoc and local-name()='Tour' and string(umbracoNaviHide) != '1']">            
                  <!-- Get upcoming departure date of each Tour -->
                  <xsl:variable name="tourDate">
                    
                    <xsl:choose>
                      <xsl:when test="salidasDiarias = 1">
                        <xsl:text>9999-01-01 00:00</xsl:text>
                      </xsl:when>
                      <xsl:otherwise>
                        <xsl:if test="count(fechasDeSalida/data/item [umbraco.library:DateGreaterThanToday(umbraco.library:FormatDateTime(departureDate, 'yyyy-MM-dd')) = 'true']) = 0">
                          <xsl:text>No hay salidas programadas</xsl:text>
                        </xsl:if>                    
                        <xsl:for-each select="fechasDeSalida/data/item [umbraco.library:DateGreaterThanToday(umbraco.library:FormatDateTime(departureDate, 'yyyy-MM-dd')) = 'true']">
                          <xsl:sort select="departureDate" order="ascending" />
                              <xsl:if test="position() &lt; 2">
                                <xsl:value-of select="departureDate"/>
                              </xsl:if>
                        </xsl:for-each>                  
                      </xsl:otherwise>
                    </xsl:choose>
                    
                  </xsl:variable>
                  
                  <!-- Add logic for field of interest -->
                  <tour id="{@id}" title="{@nodeName}" price="{doubleroomPrice}">
                      <xsl:attribute name="date">
                        <xsl:value-of select="$tourDate"/>
                      </xsl:attribute>
                  </tour>
                </xsl:for-each>
              </tourslist>
            </xsl:variable>
      
            <xsl:variable name="tourItems" select="msxml:node-set($tmpTourItems)" />
      
            <xsl:variable name="numberOfRecords" select="count($tourItems/tourslist/tour)"/>
            
            <div id="next">
              <xsl:if test="local-name($currentPage) != 'JWeb_Home'">
                <xsl:attribute name="class">
                  <xsl:text>inside</xsl:text>
                </xsl:attribute>              
              </xsl:if>
              <h3>Próximos viajes</h3>
              <ul>
                <xsl:for-each select="$tourItems/tourslist/tour">
                  <xsl:sort select="@date" order="ascending"/>
                
                  <xsl:if test="position() &lt;= $resultsPerPage and @date != 'No hay salidas programadas'">         

                      <li>
                        <xsl:if test="position() = $resultsPerPage or position() = last()">
                          <xsl:attribute name="class">
                            <xsl:text>last</xsl:text>
                          </xsl:attribute>              
                        </xsl:if>
                        <xsl:choose>
                          <xsl:when test="@date = '9999-01-01 00:00'">
                            <xsl:text>Salidas diarias</xsl:text>
                          </xsl:when>
                          <xsl:otherwise>
                            <xsl:value-of select="umbraco.library:FormatDateTime(@date, 'dd/MM/yyyy')"/>              
                          </xsl:otherwise>
                        </xsl:choose>                    
                        <br/>
                        <a href="{umbraco.library:NiceUrl(@id)}" title="{@title}"><xsl:value-of select="umbraco.library:TruncateString(umbraco.library:StripHtml(@title), 255,'...')"/></a>
                        <br/>
                        <span><xsl:text>desde </xsl:text><xsl:value-of select="@price"/><xsl:text> </xsl:text></span>
                      </li>
     
                  </xsl:if>
                  
                </xsl:for-each>
              </ul>
              <a class="seeMore" href="#">ver más +</a>
            </div>

    </xsl:template>

    </xsl:stylesheet>

Please Sign in or register to post replies

Write your reply to:

Draft