[prev in list] [next in list] [prev in thread] [next in thread] 

List:       xsl-list
Subject:    Re: [xsl] Grouping by distinct combinations of descendant elements in xsl 2.0 and xpath 2.0
From:       Simon Pepping <sampepping () gmail ! com>
Date:       2012-02-13 13:29:06
Message-ID: CALjo=uT5YVn8CH8F=uHYtE+VYgL5muOSdR9UV83AG61MGexxEQ () mail ! gmail ! com
[Download RAW message or body]

<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@gmail.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@lists.mulberrytech.com>
--~--

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic