[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Flat bullets to nested ul

Subject: Flat bullets to nested ul
From: Emma Burrows <Emma.Burrows@xxxxxxxxxxx>
Date: Fri, 1 Jul 2011 16:40:07 +0100
 Flat bullets to nested ul
I am using XSLT 2.0 with Oxygen 12 and Saxon EE. I am currently working on a
document that features nested bulleted lists with sub-paragraphs, but
expressed as a flat list of paragraph elements. I am converting this to a
DITA-compliant structure. I have had some success getting the first level
working, and the bulleted paragraphs on the second level, but I'm just lacking
the extra bit to get sub-paragraphs included in the second level <li>.

But let me illustrate the problem better.

Here is my input:

<wrapper>
  <para style="PLAIN">Normal para not involved in the bullets at all.</para>
  <para style="BULLET">bullet level 1</para>
  <para style="INDENT">para involved in level 1</para>
  <para style="BULLINDENT">bullet level 2</para>
  <para style="INDENT2">mixed content</para>
  <para style="INDENT2">mixed content</para>
  <para style="PLAIN">The list is finished</para>
</wrapper>

Here is the desired output:

<p>Normal para not involved in the bullets at all.</para>
<ul>
  <li>bullet level 1
    <p>para involved in level 1</para>
   <ul>
      <li>bullet level 2
         <p>mixed content</p>
         <p>mixed content</p>
      </li>
   </ul>
  </li>
</ul>
<p>The list is finished</para>

But currently, I get:

<p>Normal para not involved in the bullets at all.</para>
<ul>
  <li>bullet level 1
    <p>para involved in level 1</para>
   <ul>
      <li>bullet level 2</li>
   </ul>
  </li>
</ul>
<p>mixed content</p>
<p>mixed content</p>
<p>The list is finished</para>

So I'm nearly there but not quite. The relevant parts of my template are as
follows:

  <xsl:template match="wrapper">
    <xsl:for-each-group select="node()"
      group-adjacent="boolean(self::para[@style='BULLET']|self::para[@style='
INDENT']|self::para[@style='BULLINDENT']|para[@style='INDENT2'])">
      <xsl:choose>
        <xsl:when test="current-grouping-key()">
          <xsl:call-template name="makeList">
            <xsl:with-param name="paralist" select="current-group()"/>
          </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
          <xsl:apply-templates select="current-group()"/>
        </xsl:otherwise>
      </xsl:choose>
    </xsl:for-each-group>
  </xsl:template>

  <xsl:template name="makeList">
    <xsl:param name="paralist"/>
    <xsl:variable name="firstpara"
select="($paralist/self::para[@style='BULLET'])[1]"/>
    <xsl:apply-templates select="$paralist[not(. >> $firstpara)] except
$firstpara"/>
    <xsl:if test="$firstpara">
      <ul>
        <xsl:for-each-group select="$paralist[not($firstpara >> .)]"
          group-starting-with="para[not($firstpara/@style ne @style)]">
          <li>
            <xsl:apply-templates select="current-group()[1]"/>
            <xsl:if test="current-group()[2]">
              <xsl:call-template name="makeSubList">
                <xsl:with-param name="paralist"
select="current-group()[position()!=1]"/>
              </xsl:call-template>
            </xsl:if>
          </li>
        </xsl:for-each-group>
      </ul>
    </xsl:if>
  </xsl:template>

  <xsl:template name="makeSubList">
    <xsl:param name="paralist"/>
    <xsl:variable name="firstpara"
select="($paralist/self::para[@style='BULLINDENT'])[1]"/>
    <xsl:apply-templates select="$paralist[not(. >> $firstpara)] except
$firstpara"/>
    <xsl:if test="$firstpara">
      <ul>
        <xsl:for-each-group select="$paralist[not($firstpara >> .)]"
          group-starting-with="para[not($firstpara/@style ne @style)]">
          <li>
            <xsl:apply-templates select="current-group()[1]"/>
            <xsl:if test="current-group()[2]">
              <xsl:call-template name="makeSubList">
                <xsl:with-param name="paralist"
select="current-group()[position()!=1]"/>
              </xsl:call-template>
            </xsl:if>
          </li>
        </xsl:for-each-group>
      </ul>
    </xsl:if>
  </xsl:template>

It may be that this is completely the wrong way to go about it, so I'm open to
suggestions. I *think* they only have two levels of nesting but I noticed an
INDENT3 in their DTD so I am afraid I may need something more scalable.

Thanks!

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.