xsl-list
[Top] [All Lists]

RE: [xsl] RE: Flat bullets to nested ul

2011-07-04 03:36:44
Thank you very much for the link, Eliot. I'll have a look at that, and it's all 
the more appropriate as I'm actually using DITA for Publishers and the 
Word2DITA aspect may well come into play.

(By the way is there a complete reference for D4P? The documentation promises 
one but doesn't seem to deliver)


-----Original Message-----
From: Eliot Kimber [mailto:ekimber(_at_)reallysi(_dot_)com]
Sent: 01 July 2011 20:34
To: xsl-list
Subject: Re: [xsl] RE: Flat bullets to nested ul

You have apply the same logic to the subgroups. So you group everything with
level one groups, then for each of those groups, group level 2 groups, and
so on.

The code here:

 http://dita4publishers.svn.sourceforge.net/viewvc/dita4publishers/trunk/too
lkit_plugins/net.sourceforge.dita4publishers.word2dita/xsl/simple2dita.xsl?v
iew=log

Is a fully-working sample of taking flat content (paragraphs and character
runs) and generating DITA markup from it, including lists.

This is part of the DITA for Publishers word2dita transform. The
simple2dita.xsl file takes a "simple" XML file, which is a more generic
representation of typical word processing data, and converts it to arbitrary
DITA markup based on a style-to-tag mapping defined in a separate
configuration file.

From your sample you might be able to adapt this to your data by generating
the "simpleWP" format from it.

Cheers,

Eliot

On 7/1/11 10:56 AM, "Emma Burrows" <Emma(_dot_)Burrows(_at_)rpharms(_dot_)com> 
wrote:

Damn, I knew I'd find the solution as soon as I sent this:

<xsl:for-each-group select="node()"

group-adjacent="boolean(self::para[@style='BULLET']|self::para[@style='INDENT'
]|self::para[@style='BULLINDENT']|para[@style='INDENT2'])">

should of course be

<xsl:for-each-group select="node()"

Group-adjacent="boolean(self::para[@style='BULLET']|self::para[@style='INDENT'
]|self::para[@style='BULLINDENT']|self::para[@style='INDENT2'])">

*facepalm*

Having said that, suggestions on a scalable solution would be welcome before I
come across the dreaded <para @style='BULLINDENT2'>/<para @style='INDENT3'>
combination. :)


-----Original Message-----
From: Emma Burrows [mailto:Emma(_dot_)Burrows(_at_)rpharms(_dot_)com]
Sent: 01 July 2011 16:40
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] 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!


--~------------------------------------------------------------------
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>
--~--


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________

______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________

--~------------------------------------------------------------------
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>
--~--


--
Eliot Kimber
Senior Solutions Architect
"Bringing Strategy, Content, and Technology Together"
Main: 512.554.9368
www.reallysi.com
www.rsuitecms.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>
--~--


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email
______________________________________________________________________

--~------------------------------------------------------------------
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>
--~--

<Prev in Thread] Current Thread [Next in Thread>