xsl-list
[Top] [All Lists]

Re: [xsl] Grouping by distinct combinations of descendant elements in xsl 2.0 and xpath 2.0

2012-02-13 07:29:21
<xsl:for-each-group select="$ap-groups"
group-by="xx:get-dates(Appointment/@Date,'')">

should be replaced by a simple call to string-join:

<xsl:for-each-group select="$ap-groups"
group-by="string-join(Appointment/@Date,':')">

Simon

On Mon, Feb 13, 2012 at 14:02, Simon Pepping <sampepping(_at_)gmail(_dot_)com> 
wrote:
Hi,

This does the grouping that you want:

  <xsl:template match="/">
    <xsl:variable name="appointments" as="element(Appointment)+">
      <xsl:for-each select="//Invitee">
        <Appointment Date="{../@Date}" TimeOfDay="{../@TimeOfDay}"
AppointmentType="{../@AppointmentType}"
          Firstname="{@Firstname}" Surname="{@Surname}"
Name="{concat(@Firstname,@Surname)}"/>
      </xsl:for-each>
    </xsl:variable>
    <xsl:variable name="ap-groups" as="element(ap-group)+">
      <xsl:for-each-group select="$appointments"
group-by="concat(@TimeOfDay,'-',@AppointmentType,'-',@Name)">
        <ap-group key="{current-grouping-key()}">
          <xsl:for-each select="current-group()">
            <xsl:copy-of select="."/>
          </xsl:for-each>
        </ap-group>
      </xsl:for-each-group>
    </xsl:variable>
    <xsl:variable name="ap-groups-by-set">
      <xsl:for-each-group select="$ap-groups"
group-by="xx:get-dates(Appointment/@Date,'')">
        <ap-group-by-set key="{current-grouping-key()}">
          <xsl:for-each select="current-group()">
            <xsl:copy-of select="."/>
          </xsl:for-each>
        </ap-group-by-set>
      </xsl:for-each-group>
    </xsl:variable>
    <Appointments>
      <xsl:for-each select="$ap-groups-by-set">
        <xsl:copy-of select="."/>
      </xsl:for-each>
    </Appointments>
  </xsl:template>

  <xsl:function name="xx:get-dates">
    <xsl:param name="Dates"/>
    <xsl:param name="dates"/>
    <xsl:choose>
      <xsl:when test="$Dates">
        <xsl:variable name="dates-c">
          <xsl:if test="$dates">
            <xsl:text>:</xsl:text>
          </xsl:if>
        </xsl:variable>
        <xsl:value-of
select="xx:get-dates($Dates[position()!=1],concat($dates,$dates-c,$Dates[1]))"/>
      </xsl:when>
      <xsl:otherwise>
        <xsl:value-of select="$dates"/>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:function>

--~------------------------------------------------------------------
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>