xsl-list
[Top] [All Lists]

Re: [xsl] for-each-group

2018-03-28 11:33:54
If you simply want to distinguish figures from everything else then you can 
make the grouping key the same for all non-figure elements and unique for 
figures, e.g.:

 

group-adjacent="if (self::figure) then concat(‘figure-‘, position()) else 
‘not-a-figure’))"

 

I constructed the keys to be clear when reflected e.g., in messages for 
debugging purposes.

 

Cheers,

 

Eliot

--

Eliot Kimber

http://contrext.com

 

 

From: "Rick Quatro rick(_at_)rickquatro(_dot_)com" 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com>
Reply-To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Date: Wednesday, March 28, 2018 at 11:22 AM
To: <xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com>
Subject: Re: [xsl] for-each-group

 

OK, I think I get it. You are grouping on a string derived from the node name 
instead of the node itself. This doesn't work for my general intent, because 
the other elements may not all be the same. For example, I might have this:

 

<steps>

  <step>

    <para>Intro stuff</para>

    <para>More intro stuff</para>

    <figure/>

    <figure/>

    <para>Conclusion stuff</para>

    <table>More conclusion stuff</table>

    <para>More conclusion stuff</para>

  </step>

</steps>

 

and I would want the three elements following the last figure to be in a single 
group. But now that I see what you are doing, I will try to work it out. Thanks.

 

Rick

 

From: Michael Kay mike(_at_)saxonica(_dot_)com 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> 
Sent: Wednesday, March 28, 2018 12:06 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: Re: [xsl] for-each-group

 

Try group-adjacent="concat(local-name(), if (self::figure) then position() else 
0))"

 

which will work for your example though it may not match your general intent...

 

Michael Kay

Saxonica

 




On 28 Mar 2018, at 16:53, Rick Quatro rick(_at_)rickquatro(_dot_)com 
<xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com> wrote:

 

Hi All,

 

I have a <step> element that looks something like this:

 

<steps>

  <step>

    <para>Intro stuff</para>

    <para>More intro stuff</para>

    <figure/>

    <figure/>

    <para>Conclusion stuff</para>

    <para>More conclusion stuff</para>

  </step>

</steps>

 

I want 4 separate groups:

 

1) First two <para> elements.

2) First <figure>

3) Second <figure>

4) Last two <para> elements.

 

Here is my stylesheet:

 

<?xml version="1.0" encoding="UTF-8"?>

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";

    xmlns:xs="http://www.w3.org/2001/XMLSchema";

    exclude-result-prefixes="xs"

    version="2.0">

    

    <xsl:template match="/steps">

        <xsl:apply-templates select="step"/>

    </xsl:template>

    

    <xsl:template match="step">

        <xsl:for-each-group select="*" group-starting-with="figure">

            <xsl:message select="count(current-group())"></xsl:message>

        </xsl:for-each-group>

    </xsl:template>

    

</xsl:stylesheet>

 

I get the first two groups, but the last two <para> elements are part of the 
last <figure>'s group instead of being separate.

 

I tried using group-by="figure" but I don't get any output. Any help would be 
appreciated. Thank you very much.

 

Rick

 

Rick Quatro

Carmen Publishing Inc.

rick(_at_)frameexpert(_dot_)com

FrameMaker toys: www.frameexpert.com/store

585-366-4017

 

 

 

XSL-List info and archive

EasyUnsubscribe (by email)

 

XSL-List info and archive 

EasyUnsubscribe (by email) 

XSL-List info and archive 

EasyUnsubscribe (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>