I don't know, there's something about the grouping attributes in
xsl-for-each-group I just don't seem to get, perhaps Michael could
comment?
Most of XSLT2 I just absorb and hardly ever refer to the spec, but I
_always_ have to check up the definition of for-each-group to check
which grouping attributes take a pattern, and which take an expression.
In the example below, the first, using group-adjacent, takes an
expression, but the second, using group-starting-with takes a pattern.
As is usally the case I got that wrong first time round. I must be
missing the "idea" behind this split, usually with XSL if you think
about things the right way, the xslt solution seesm perfectly natural,
it's just a matter of getting the brain to think the right way....
David
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output indent="yes"/>
<xsl:template match="section">
<section>
<xsl:for-each-group select="para"
group-adjacent="replace(@class,'source','para')">
<xsl:choose>
<xsl:when test="current-grouping-key() = 'epigraphpara'">
<epigraph>
<xsl:apply-templates select="current-group()"/>
</epigraph>
</xsl:when>
<xsl:otherwise>
<xsl:for-each-group select="current-group()"
group-starting-with="para[inline[ends-with(@class,'title')]]">
<subsection>
<title><xsl:apply-templates select="."/></title>
<xsl:apply-templates select="current-group()[position()!=1]"/>
</subsection>
</xsl:for-each-group>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
</section>
</xsl:template>
<xsl:template match="*">
<xsl:copy>
<xsl:copy-of select="@*"/>
<xsl:apply-templates/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
$ saxon8 epi.xml epi.xsl
<?xml version="1.0" encoding="UTF-8"?>
<section>
<epigraph>
<para class="epigraphpara">...</para>
<para class="epigraphpara">...</para>
<para class="epigraphpara">...</para>
<para class="epigraphpara">...</para>
<para class="epigraphsource">...</para>
</epigraph>
<subsection>
<title>
<para class="subsection1para">
<inline class="subsection1title">...</inline>
</para>
</title>
<para class="subsection1para">...</para>
<para class="subsection1para">...</para>
<para class="subsection1para">...</para>
<para class="subsection1para">...</para>
<para class="subsection1para">...</para>
<para class="subsection1para">...</para>
<para class="subsection1para">...</para>
<para class="subsection1para">...</para>
</subsection>
<subsection>
<title>
<para class="subsection1para">
<inline class="subsection1title">...</inline>
</para>
</title>
<para class="subsection1para">...</para>
<para class="subsection1para">...</para>
<para class="subsection1para">...</para>
<para class="subsection1para">...</para>
</subsection>
</section>
--~------------------------------------------------------------------
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>
--~--