Re: [xsl] Help me to select group based on maximum value

Subject: Re: [xsl] Help me to select group based on maximum value
From: "Imsieke, Gerrit, le-tex" <gerrit.imsieke@xxxxxxxxx>
Date: Fri, 31 Aug 2012 17:34:04 +0200
On 2012-08-31 17:04, Michael Kay wrote:
Untested solution:

<xsl:for-each-group select="Product" group-adjacent="@id">

should be group-by, of course


   <xsl:for-each select="current-group()">
       <xsl:sort select="number(rank)" order="descending"/>
       <xsl:if test="position() = 1">
          <xsl:copy-of select="."/>
       </xsl:if>
    </xsl:for-each>
</xsl:for-each-group>

The complete template might look like this:


  <xsl:template match="Products">
    <xsl:copy>
      <xsl:copy-of select="@*, Manager" />
      <xsl:for-each-group select="Product" group-by="@id">
        <xsl:for-each select="current-group()">
          <xsl:sort select="number(rank)" order="descending"/>
          <xsl:if test="position() = 1">
            <xsl:copy-of select="."/>
          </xsl:if>
        </xsl:for-each>
      </xsl:for-each-group>
      <xsl:copy-of select="* except (Manager union Product)" />
    </xsl:copy>
  </xsl:template>

Current Thread