RE: [xsl] exit <xsl:for-each> or change <xsl:variable>

Subject: RE: [xsl] exit <xsl:for-each> or change <xsl:variable>
From: "Michael Kay" <michael.h.kay@xxxxxxxxxxxx>
Date: Tue, 2 Apr 2002 11:14:32 +0100
> Here is the actual problem. If the processor comes across a
> $next-table$
> cell it should:
>
>           <xsl:if test="(cell[1]/data)='$next-table$'">
>             </table><table border="1">
>           </xsl:if>
>
> but that is not possible is it. Is there a way to do this? I
> would like to
> end the current table and start a new one when the value
> '$next-table$'
> shows up.

You're thinking procedurally, and you're thinking in terms of writing tags,
rather than writing nodes.

This is a grouping problem. Use standard grouping techniques
(www.jenitennison.com/xslt/grouping). The grouping key (the property of a
node that determines whether two nodes are in the same group) in your case
is something like:

generate-id(preceding-sibling::cell[data='$next-table'][1])

that is, two nodes are in the same group if they both have the same node as
the most recent $next-table$ cell.

With XSLT 2.0 / Saxon 7.0 you can use pattern-based grouping:

<xsl:for-each-group select="cell"
group-starting-at="cell[data='$next-table']">
  <table>
    <xsl:for-each select="current-group()">
      <tr>
        ....
      </tr>
    </xsl:for-each>
  </table>
</xsl:for-each-group>

Michael Kay
Software AG
home: Michael.H.Kay@xxxxxxxxxxxx
work: Michael.Kay@xxxxxxxxxxxxxx


 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread