I think you need to tackle these problems in multiple phases, and sometimes
it seems to be best to do them bottom-up.
Grouping the adjacent bullets can use
<xsl:for-each-group select="node()" group-adjacent="boolean(self::bullet)">
<xsl:choose>
<xsl:when test="current-grouping-key()">
<ul>
<xsl:copy-of select="current-group()"/>
</ul>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="current-group()"/>
</xsl:otherwise>
</xsl:choose>
</xsl:for-each-group>
For the h1, h2, h3 etc, use group-starting-with on the level-3 headings
first:
<xsl:for-each-group select="node()" group-starting-with="head3">
<div3>
<xsl:if test="current-group()[self::head3]">
<head><xsl:value-of select="current-group()[self::head3]"/></head>
</xsl:if>
<xsl:copy-of select="current-group()[not(self::head3)]"/>
</div3>
</xsl:for-each>
Then repeat for level-2 and finally for level-1.
Michael Kay
# -----Original Message-----
# From: owner-xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
[mailto:owner-xsl-
# list(_at_)lists(_dot_)mulberrytech(_dot_)com] On Behalf Of
David(_dot_)Pawson(_at_)rnib(_dot_)org(_dot_)uk
# Sent: 09 March 2004 14:56
# To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
# Subject: [xsl] positional grouping xslt2
#
# I'm trying .. and failing, to use the xslt 2 grouping ideas
# picking on a starting element and grouping using the group-starting-with
# attribute.
#
# The w3c examples are too simplistic to work here.
#
#
#
#
# xml file,
#
# <article>
# <head1> An Example Twiki Document</head1>
# <hr/>a para to show content in this level 1
# <head1> This is a level 1 heading
# A filler paragraph</head1>
# <head2> This is a level 2 heading
# A filler paragraph</head2>
# <head3> And a level 3 heading. Never more than two linefeeds between
# content. Othewise it shows up as a paragraph!</head3>
# <p>A straightforward paragraph requires no special formatting. It can
# include <b>bold</b> text, <i>italic</i> text and
# <literal>monotype</literal>
# text. Note that
# bold and italic will be converted to docbook emphasis markup.</p>
# <p>Note that the star and underscore must be tight up to the marked up
# text,
# as per the wiki requirment</p>
# <head2> Other markup.</head2>
# <p>For lists, use </p>
# <bull1> Three spaces (not a tab) then the star</bull1>
# <bull1> Other List items then follow</bull1>
# <bull1> Third list item</bull1>
# <p>For ordered (itemised) lists,</p>
# <litem> ITem one</litem>
# <litem> item two</litem>
# <litem> and so on</litem>
# <litem>Note also that you only need add the number 1, not increment it
# each time.</litem>
# <litem>And that if you insert spaces after the number, they will be
# copied over.</litem>
# <p>Display lists, or definition lists, contain a term and its
# explanation. Three spaces followed by the dollar symbol prefix the
# term, the colon terminates the term and starts the definition. The
# newline terminates the definition</p>
# </article>
#
#
# etc.
# I.e. flat, no structure.
# I want to use the positional grouping idea from xslt 2 to group under
# section wrappers,
# With a root template as below, I'm stuck figuring out where the nesting is
# needed.
# It seems like a pull only solution is needed, since apply templates will
# duplicate
# the output.
# I'm currently getting the head1 stuff to work,
# but failing with the second level.
# Since the bull1 - wanted as docbook itemizedlist - also needs this
# sort of grouping treatment, I'm looking for a structure which works
# with this form of input.
# I've added some debug to find out if its working.... and its not.
#
# any help appreciated.
#
# the required output is a nested suite of section tags wrapping
# what are now sibling head1 head2 head3 elements.
# bull1 lists should fit in with the current hierarchy.
#
#
# stylesheet.
#
# <xsl:template match="/">
# <xsl:for-each-group select="article/*" group-starting-with="head1">
# <section>
# <head><xsl:value-of select="self::head1"/></head>
#
# <xsl:for-each-group select="current-group()" group-starting-with="head2">
# <section2>
# <head2><xsl:value-of select="self::head2"/></head2>
# Debug: head2 children are:
# <xsl:for-each select="current-group()">
# <xsl:value-of select="name()"/> <xsl:text> </xsl:text>
# </xsl:for-each>
# </section2>
# </xsl:for-each-group>
# </section>
# </xsl:for-each-group>
#
# <xsl:for-each-group select="*" group-starting-with="bull1">
# <itemizedlist>
# <xsl:for-each select="current-group()">
# <listitem>
# <xsl:apply-templates mode="struct"/>
# </listitem>
# </xsl:for-each>
# </itemizedlist>
# </xsl:for-each-group>
# </article>
# </xsl:template>
#
# <xsl:template match="p" mode="struct">
# <para><xsl:apply-templates mode="struct"/></para>
# </xsl:template>
#
# Other inline markup is similarly moded.
#
#
#
#
# Regards DaveP.
#
# **** snip here *****
#
# -
# DISCLAIMER:
#
# NOTICE: The information contained in this email and any attachments is
# confidential and may be privileged. If you are not the intended
# recipient you should not use, disclose, distribute or copy any of the
# content of it or of any attachment; you are requested to notify the
# sender immediately of your receipt of the email and then to delete it
# and any attachments from your system.
#
# RNIB endeavours to ensure that emails and any attachments generated by
# its staff are free from viruses or other contaminants. However, it
# cannot accept any responsibility for any such which are transmitted.
# We therefore recommend you scan all attachments.
#
# Please note that the statements and views expressed in this email and
# any attachments are those of the author and do not necessarily represent
# those of RNIB.
#
# RNIB Registered Charity Number: 226227
#
# Website: http://www.rnib.org.uk
#
# XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list