I think you may be better off keeping the for-each-group you had that
grouped Stamps by year. Add an extra one around the <h6>...</h6>
tags, just like Michael showed, but with select="current-group()"
instead of select="Stamp".
This would eliminate the need for the test around the <h2>...</h2>.
It would also be more robust in case you ever get input where the
Stamps aren't in order by year, or other corner cases that could cause
the group-adjacent to produce incorrect results without first doing
the group-by on @year. (Try moving stamp 59 after stamp 96 in your
example, or just changing "59" to "95".)
-Brandon :)
On Tue, Aug 9, 2011 at 5:04 PM, Mark <mark(_at_)knihtisk(_dot_)org> wrote:
Thanks, Michael,
Worked, with a bit of adjustment to single up the date element:
<xsl:if test="not(preceding-sibling::Stamp[1]/Date/@year eq Date/@year)">
<h2>
<xsl:value-of select="Date/@year"></xsl:value-of>
</h2>
</xsl:if>
As always, help is great on this list.
Mark
-----Original Message----- From: Michael Kay Sent: Tuesday, August 09, 2011
1:42 PM To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com Subject: Re:
[xsl] Subdividing
sets of elements by sequence identifiers
On 09/08/2011 20:37, Mark wrote:
I have an "almost works" situation. The template and simplified input are
below. What I want to is "re-wrap images with consecutive image numbers (in
my output example "27,28,29") in a new <h6> element for HTML display
purposes. To do this,at the beginning of such a sequence, I must close off
the <h6> inserted by the current template with a </h6> and open a new <h6>.
Here only one sequence is shown, but several are possible within each
element.
I suspect I am thinking about this procedurally rather than imperatively,
and thus cannot see the forest for the trees. All suggestions appreciated.
Actually I think you are having trouble seeing the trees for the tags...
There's a David Carlisle trick for this one:
<xsl:for-each-group select="Stamp" group-adjacent="@image-number -
position()">
<h6>
...
</h6>
</xsl:for-each-group>
Three consecutive elements with image numbers 27, 28, 29 in positions 5, 6,
7 will have grouping keys 22, 22, 22, so they end up in the same group.
Michael Kay
Saxonica
Mark
Selection from current output:
<List>
<h1>Art on Stamps</h1>
<h2>1993</h2>
<h6>
<a href="../img/1993/5.jpg" target="_blank">
<img src="../img/1993/5.jpg" alt="stamp image" width="100"
border="2px"></img>
</a>
<!-- ********** need to insert </h6><h6> here ************* -->
<a href="../img/1993/27.jpg" target="_blank">
<img src="../img/1993/27.jpg" alt="stamp image" width="100"
border="2px"></img>
</a>
<a href="../img/1993/28.jpg" target="_blank">
<img src="../img/1993/28.jpg" alt="stamp image" width="100"
border="2px"></img>
</a>
<a href="../img/1993/29.jpg" target="_blank">
<img src="../img/1993/29.jpg" alt="stamp image" width="100"
border="2px"></img>
</a>
</h6>
......
</List>
My Template:
<xsl:template match="Item">
<h1>
<xsl:value-of select="@concept"></xsl:value-of>
</h1>
<xsl:for-each-group select="Stamp" group-by="Date/@year">
<xsl:sort select="Date/@year"></xsl:sort>
<h2>
<xsl:value-of select="Date/@year"></xsl:value-of>
</h2>
<h6>
<xsl:for-each select="current-group()">
<xsl:variable name="image" select="concat('../img/', Date/@year, '/',
@image-number, '.jpg')"></xsl:variable>
<a href="{$image}" target="_blank">
<img src="{$image}" alt="stamp image" width="100" border="2px"></img>
</a>
</xsl:for-each>
</h6>
</xsl:for-each-group>
</xsl:template>
My Input: (simplified to a single <Item> from the <List>
<List>
<Item concept="Art on Stamps">
<Stamp image-number="5">
<Date year="1993"></Date>
</Stamp>
<Stamp image-number="27" >
<Date year="1993"></Date>
</Stamp>
<Stamp image-number="28">
<Date year="1993"></Date>
</Stamp>
<Stamp image-number="29" >
<Date year="1993"></Date>
</Stamp>
<Stamp image-number="42" >
<Date year="1994"></Date>
</Stamp>
<Stamp image-number="43">
<Date year="1994"></Date>
</Stamp>
<Stamp image-number="44">
<Date year="1994"></Date>
</Stamp>
<Stamp image-number="57" >
<Date year="1994" ></Date>
</Stamp>
<Stamp image-number="58">
<Date year="1994"></Date>
</Stamp>
<Stamp image-number="59">
<Date year="1994"></Date>
</Stamp>
<Stamp image-number="96">
<Date year="1995"></Date>
</Stamp>
<Stamp image-number="97" >
<Date year="1995"></Date>
</Stamp>
<Stamp image-number="98">
<Date year="1995" ></Date>
</Stamp>
</Item>
</List>
--~------------------------------------------------------------------
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(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
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(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
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(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--
--~------------------------------------------------------------------
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(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--