RE: [xsl] XSLT grouping without Muenchen Method

Subject: RE: [xsl] XSLT grouping without Muenchen Method
From: "Kienle, Steven C" <steven.c.kienle@xxxxxxxxxx>
Date: Tue, 31 Aug 2004 08:27:25 -0400
Ismakl,

You can combine Anton's method into one transform.  With some rewriting, you
can put his Pass1 transform into a variable, then actually use that variable
in the Pass2 transform rather than an input file.  I've done this below:

<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:output method="text"/>

  <xsl:variable name="pass1">
    <xsl:for-each select="/root/object">
      <object name="{@name}"
        instance="{concat('Instance', instance/@number)}">
        <xsl:attribute name="interval">
          <xsl:value-of
            select="substring-before(instance/sample/@date_time, ':')"/>
          <xsl:call-template name="calculate-interval">
            <xsl:with-param name="time"
              select="substring-after(instance/sample/@date_time, ':')"/>
          </xsl:call-template>
        </xsl:attribute>
      </object>
    </xsl:for-each>
  </xsl:variable>

  <xsl:template name="calculate-interval">
    <xsl:param name="time"/>
    <xsl:variable name="hour"
      select="number(substring-before($time, ':'))"/>
    <xsl:choose>
      <xsl:when test="$hour &lt; 15">:00:00</xsl:when>
      <xsl:when test="$hour &lt; 30">:15:00</xsl:when>
      <xsl:when test="$hour &lt; 45">:30:00</xsl:when>
      <xsl:otherwise>:45:00</xsl:otherwise>
    </xsl:choose>
  </xsl:template>

  <xsl:template match="/">
    <xsl:apply-templates select="$pass1/object">
      <xsl:sort select="@interval"/>
      <xsl:sort select="@instance"/>
    </xsl:apply-templates>
  </xsl:template>

  <xsl:template match="object">
    <xsl:variable name="interval" select="@interval"/>
    <xsl:variable name="instance" select="@instance"/>
    <xsl:if
      test="not(preceding-sibling::object[@interval=$interval and
@instance=$instance])">
      <!-- first of group -->
      <xsl:apply-templates
        select="self::object | following-sibling::object[@interval=$interval
and @instance=$instance]"
        mode="write"/>
      <xsl:value-of select="@instance"/>
      <xsl:text>;</xsl:text>
      <xsl:value-of select="@interval"/>
      <xsl:text>&#xA;</xsl:text>
    </xsl:if>
  </xsl:template>

  <xsl:template match="object" mode="write">
    <xsl:variable name="interval" select="@interval"/>
    <xsl:variable name="instance" select="@instance"/>
    <xsl:value-of select="@name"/>
    <xsl:choose>
      <xsl:when
        test="following-sibling::object[@interval=$interval and
@instance=$instance]">
        <xsl:text>,</xsl:text>
      </xsl:when>
      <xsl:otherwise>
        <xsl:text>;</xsl:text>
      </xsl:otherwise>
    </xsl:choose>
  </xsl:template>

</xsl:stylesheet>

This works for me using Saxon 7.8, but I don't think I'm using anything
beyond what XT can do.  If this does work in XT, I'm out of ideas.

	Steve


-----Original Message-----
From: Ismael Cams [mailto:xslt@xxxxxxxxxxx]
Sent: Tuesday, August 31, 2004 1:55 AM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] XSLT grouping without Muenchen Method


On Mon, 30 Aug 2004 20:47:46 +0200
  "cking" <cking@xxxxxxxxxx> wrote:

Hello Anton,

thanks for the provided solution. Unfortunately I can not use a two step
solution, as I can only integrate one stylesheet into the application. XTh
 as a node-set function and this can indeed used as a solution for my
problem. Normally I try to avoid to use extension functions as I want to
have my stylesheets processor independent, but in this case I do not see any

other solution to solve it.


LEGAL NOTICE
Unless expressly stated otherwise, this message is confidential and may be
privileged. It is intended for the addressee(s) only. Access to this E-mail by
anyone else is unauthorized. If you are not an addressee, any disclosure or
copying of the contents of this E-mail or any action taken (or not taken) in
reliance on it is unauthorized and may be unlawful. If you are not an
addressee, please inform the sender immediately.

Current Thread