xsl-list
[Top] [All Lists]

Re: [xsl] Adjacent grouping?

2017-11-17 12:00:43
Sorry, I misread the requirement. You want a new group if the value is 30+ 
greater than the FIRST value in the previous group, whereas I thought you were 
comparing with the LAST value in the previous group.

No, I don't think this can be done with grouping: it needs full recursion (or 
in XSLT 3.0, xsl:iterate).

Using xsl:iterate it would be

<xsl:iterate select="Content">
  <xsl:param name="previous" as="xs:integer?" select="()"/>
 <xsl:choose>
    <xsl:when test="empty($previous) or xs:integer(@value) gt @previous+30">
      <Content value="{@value}"/>
      <xsl:next-iteration>
         <xsl:with-param name="previous" select="@value"/>
     </xsl:next-iteration>
    </xsl:when>
   <xsl:otherwise>
      <Content value=""/>
  </xsl:otherwise>
</xsl:choose>
</xsl:iterate>

Michael Kay
Saxonica

On 17 Nov 2017, at 17:51, Michael Kay mike(_at_)saxonica(_dot_)com 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

You want to start a new group if @value is greater than 
preceding-sibling::Content/@value.

So you can use

<xsl:for-each-group select="Content" group-starting-with="*[number(@value) gt 
number(../preceding-sibling::*/@value) + 30]">
   ...
</xsl:for-each-group>

Michael Kay
Saxonica 

On 17 Nov 2017, at 17:43, rus tle 
profrustyleafiii(_at_)yahoo(_dot_)co(_dot_)uk 
<mailto:profrustyleafiii(_at_)yahoo(_dot_)co(_dot_)uk> 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com 
<mailto:xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com>> wrote:

Hello All,

I am trying to remove attribute values in a list based on a frequency 
parameter.

Is this possible in XSLT 2? I cannot see how to tackle the problem without 
being able to store the last attribute value added to the result tree so 
that I can compare against it for the following attribute values? I am told 
that there is no way to query the result tree and so I am at a loss as to 
whether XSLT can actually do what I require?

To illustrate, please see the example below.

The frequency parameter is 30. I would like to remove all values that are 
"within 30" of the last value used. If the first value is 0 then I would 
like to remove all the following attribute values that are less than 30 plus 
the last value added to the result tree (in this case 0). The only way I can 
think to do this is by somehow caching the last value that was copied to the 
result tree so I can compare against it with the next value.

It was suggested to me that adjacent grouping my work? I am a recent 
beginner to XSLT and would love to learn more about how it might help me 
achieve the result I am looking for?

Thanks,

Rusty

Before:

<p frequency=“30">
    <Content value="0"/>
    <Content value=”10”/> 
    <Content value=”15”/> 
    <Content value=”18”/> 
    <Content value=”22”/> 
    <Content value=”26”/> 
    <Content value=”34”/> 
    <Content value=”37”/> 
    <Content value=”56”/> 
    <Content value=”99”/> 
    <Content value=”101”/>
    <Content value="115"/> 
    <Content value="118"/>
    <Content value="129"/>
</p>
After:

<p frequency="30">
    <Content value="00"/>
    <Content value=""/> 
    <Content value=""/> 
    <Content value=""/> 
    <Content value=""/> 
    <Content value=""/> 
    <Content value="34"/> 
    <Content value=""/> 
    <Content value=""/> 
    <Content value="99"/> 
    <Content value=""/>
    <Content value=""/> 
    <Content value=""/>
    <Content value="129"/>
</p>

XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <x-msg://19/-list/293509> (by email 
<applewebdata://EAB4634C-8806-4E4F-85C4-8658F324B332>)

XSL-List info and archive <http://www.mulberrytech.com/xsl/xsl-list>
EasyUnsubscribe <-list/293509> (by email <>)
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--
<Prev in Thread] Current Thread [Next in Thread>