Copied to clipboard

Flag this post as spam?

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


  • Kasper Dyrvig 246 posts 379 karma points
    Jun 06, 2011 @ 09:15
    Kasper Dyrvig
    0

    Select distinct values

    Hi

    I need to collapse a list of arrival dates to only view the unique dates.

    The data is like this:

    <arrivals>
    <arrival>
      <stayid>10399</stayid>
        <transport>Fly fra Kastrup</transport>
        <roomtype>Dubbelrum med bad/toalett</roomtype>
        <price>9995.00</price>
        <arrivaldate>12/09/2011</arrivaldate>
        <bookingurl>http://booking.domain.se/order.aspx?ps=10399</bookingurl>;
      </arrival>
    <arrival>
      <stayid>10399</stayid>
        <transport>Fly fra Aalborg</transport>
        <roomtype>Dubbelrum med bad/toalett</roomtype>
        <price>9995.00</price>
        <arrivaldate>12/09/2011</arrivaldate>
        <bookingurl>http://booking.domain.se/order.aspx?ps=10399</bookingurl>;
      </arrival>
    </arrivals>

    Now I would like to view the dates in a dropdown box. When a date is selected and the user clicks the order button he is redirected to the "bookingurl".

    Anyone who can help me getting only the unique dates?

    I have tried with Exslt.ExsltSets:distinct($list), where $list is a comma seperated list of the dates.

  • Tom Fulton 2030 posts 4996 karma points c-trib
    Jun 06, 2011 @ 17:32
    Tom Fulton
    5

    Hi Kasper,

    You can use XSLT keys for this.  Here is a simple example:

    <xsl:key name="uniqueDate" match="arrival" use="arrivaldate"/> 

    <xsl:template match="/">
      <xsl:apply-templates select="$yourXml/arrivals/arrival [generate-id() = generate-id(key('uniqueDate', arrivaldate)[1])]" mode="arrival"/>
    </xsl:template>

    <xsl:template match="arrival" mode="arrival">
    Date: <xsl:value-of select="arrivaldate" />
    </xsl:template>

    Not tested, just copied/edited from an example I posted for selecting unique Countries here.  Should work though, just replace $yourXml with wherever you are loading your custom XML from.

    Also if the dates are in different formats you can use umbraco.library:FormatDateTime on the key's use attribute and in the XPath for selecting.

    Hope this helps,
    Tom

     

     

     

  • Kasper Dyrvig 246 posts 379 karma points
    Jun 08, 2011 @ 09:50
    Kasper Dyrvig
    0

    Yaer! Thanks!

  • This forum is in read-only mode while we transition to the new forum.

    You can continue this topic on the new forum by tapping the "Continue discussion" link below.

Please Sign in or register to post replies