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

Nested list handling in WordML

Subject: Nested list handling in WordML
From: "Joga Singh Rawat jrawat@xxxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 18 Aug 2015 05:07:13 -0000
 Nested list handling in WordML
Dear experts,
I am not able to handle nested listing of WordML. Below is the details
description. Could anybody let me correct the below approach or an suggest
another approach.

Input
<w:p><w:pPr><w:listPr><w:ilvl w:val="0"/><wx:t
wx:val="1"/></w:listPr></w:pPr><w:r><w:t>first level</w:t></w:r></w:p>
<w:p><w:pPr><w:listPr><w:ilvl w:val="0"/><wx:t
wx:val="2"/></w:listPr></w:pPr><w:r><w:t>first level</w:t></w:r></w:p>
<w:p><w:pPr><w:listPr><w:ilvl w:val="1"/><wx:t
wx:val="a"/></w:listPr></w:pPr><w:r><w:t>second level</w:t></w:r></w:p>
<w:p><w:pPr><w:listPr><w:ilvl w:val="1"/><wx:t
wx:val="b"/></w:listPr></w:pPr><w:r><w:t>second level</w:t></w:r></w:p>
<w:p><w:pPr><w:listPr><w:ilvl w:val="2"/><wx:t
wx:val="i"/></w:listPr></w:pPr><w:r><w:t>third level</w:t></w:r></w:p>
<w:p><w:pPr><w:listPr><w:ilvl w:val="2"/><wx:t
wx:val="ii"/></w:listPr></w:pPr><w:r><w:t>third level</w:t></w:r></w:p>
<w:p><w:pPr><w:listPr><w:ilvl w:val="1"/><wx:t
wx:val="c"/></w:listPr></w:pPr><w:r><w:t>second level</w:t></w:r></w:p>
<w:p><w:pPr><w:listPr><w:ilvl w:val="1"/><wx:t
wx:val="d"/></w:listPr></w:pPr><w:r><w:t>second level</w:t></w:r></w:p>
<w:p><w:pPr><w:listPr><w:ilvl w:val="0"/><wx:t
wx:val="3"/></w:listPr></w:pPr><w:r><w:t>first level</w:t></w:r></w:p>
<w:p><w:pPr><w:listPr><w:ilvl w:val="0"/><wx:t
wx:val="4"/></w:listPr></w:pPr><w:r><w:t>first level</w:t></w:r></w:p>

Current output
<ol>
<li><label>1</label><p>first level</p></li>
<li><label>2</label><p>first level</p></li>
<li level="2"><label>a</label><p>second level</p></li>
<li level="2"><label>b</label><p>second level</p></li>
<li level="3"><label>i</label><p>third level</p></li>
<li level="3"><label>ii</label><p>third level</p></li>
<li level="2"><label>c</label><p>second level</p></li>
<li level="2"><label>d</label><p>second level</p></li>
<li><label>3</label><p>first level</p></li>
<li><label>4</label><p>first level</p></li>
</ol>

Expected output
<ol>
<li><label>1</label><p>first level</p></li>
<li><label>2</label><p>first level</p>
<ol>
  <li level="2"><label>a</label><p>second level</p></li>
  <li level="2"><label>b</label><p>second level</p>
  <ol>
    <li level="3"><label>i</label><p>third level</p></li>
    <li level="3"><label>ii</label><p>third level</p></li>
   </ol></li>
   <li level="2"><label>c</label><p>second level</p></li>
    <li level="2"><label>d</label><p>second level</p></li>
   </ol></li>
<li><label>3</label><p>first level</p></li>
<li><label>4</label><p>first level</p></li>
</ol>

XSLT
<xsl:template match="w:p">
  <xsl:choose>
   <xsl:when test="w:pPr/w:listPr">
    <xsl:if test="not(preceding-sibling::*[1][self::w:p/w:pPr/w:listPr])">
     <xsl:variable name="list-type">
      <xsl:call-template name="GetListType">
       <xsl:with-param name="listIndexerFont"
select="w:pPr/w:listPr/wx:font/@wx:val"/>
      </xsl:call-template>
     </xsl:variable>
     <xsl:element name="{$list-type}">
      <li>
       <xsl:if test="descendant::wx:t/@wx:val">
        <xsl:variable name="label">
         <xsl:call-template name="replace-entities">
          <xsl:with-param name="text" select="descendant::wx:t/@wx:val" />
         </xsl:call-template>
        </xsl:variable>
        <label>
         <xsl:apply-templates select="$label"/>
        </label>
       </xsl:if>
       <p><xsl:apply-templates select="w:r"/></p>
      </li>
      <xsl:apply-templates
select="following-sibling::*[1][self::w:p[w:pPr/w:listPr/w:ilvl/@w:val='0']]
| 
 
following-sibling::*[1][self::w:p[w:pPr/w:listPr]]" mode="listing"/>
     </xsl:element>
    </xsl:if>
   </xsl:when>
  </xsl:choose>
 </xsl:template>

<xsl:template match="*" mode="listing">
  <li>
   <xsl:choose>
    <xsl:when test="w:pPr/w:listPr/w:ilvl/@w:val='1'">
     <xsl:attribute name="level" select="'2'"/>
    </xsl:when>
    <xsl:when test="w:pPr/w:listPr/w:ilvl/@w:val='2'">
     <xsl:attribute name="level" select="'3'"/>
    </xsl:when>
   </xsl:choose>
   <xsl:if test="descendant::wx:t/@wx:val">
    <xsl:variable name="label">
     <xsl:call-template name="replace-entities">
      <xsl:with-param name="text" select="descendant::wx:t/@wx:val" />
     </xsl:call-template>
    </xsl:variable>
    <label>
     <xsl:apply-templates select="$label"/>
    </label>
   </xsl:if>
   <p><xsl:apply-templates select="w:r"/></p>
  </li>
  <xsl:apply-templates
select="following-sibling::*[1][self::w:p[w:pPr/w:listPr]]" mode="listing"/>
 </xsl:template>

Thanks a lot in advance.

...JSR

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.