Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old January 7th, 2006, 05:16 AM
Authorized User
 
Join Date: Dec 2005
Posts: 71
Thanks: 10
Thanked 0 Times in 0 Posts
Default Multiple Grouping in List

I have an XML.
--------------
<artbody>
<sec>
<subsec>
               <list>1. First level nunmbered list</list>
               <list>2. First level nunmbered list</list>
                    <sublist>(a) Second level nunmbered list</sublist>
                    <sublist>(b) Second level nunmbered list</sublist>
               <list>3. First level nunmbered list</list>
                    <sublist>I) Second level nunmbered list</sublist>
                        <sub_sublist>A. Third level nunmbered list</sub_sublist>
                        <sub_sublist>B. Third level nunmbered list</sub_sublist>
                    <sublist>II) Second level nunmbered list</sublist>
                    <sublist>III) Seconcd level nunmbered list</sublist>
               <list>4. First level nunmbered list</list>
               <list>5. First level nunmbered list</list>
               <list>6. First level nunmbered list</list>
                    <sublist>I) Second level nunmbered list</sublist>
                    <sublist>II) Second level nunmbered list</sublist>
               <list>7. First level nunmbered list</list>
                    <sublist>I) Second level nunmbered list</sublist>
                        <sub_sublist>A. Third level nunmbered list</sub_sublist>
                        <sub_sublist>B. Third level nunmbered list</sub_sublist>
                    <sublist>I) Second level nunmbered list</sublist>
                    <sublist>II) Second level nunmbered list</sublist>
               <list>8. First level nunmbered list</list>

</subsec>
</sec>
</artbody>

Used XSL.
---------
<?xml version="1.0" encoding="iso-8859-1"?>
<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">


<xsl:output method="xml" indent="yes"/>

<xsl:template match="node() | @*">
  <xsl:copy>
    <xsl:apply-templates select="node() | @*" />
  </xsl:copy>
</xsl:template>


<xsl:template match="list | sublist | sub_sublist | sub_sub_sublist">
  <xsl:if test="not(name(preceding-sibling::*[1]) = 'list')">
    <xsl:if test="not(name(preceding-sibling::*[1]) = 'sublist')">
    <xsl:if test="not(name(preceding-sibling::*[1]) = 'sub_sublist')">
    <xsl:if test="not(name(preceding-sibling::*[1]) = 'sub_sub_sublist')">
    <done>
    <xsl:copy-of select=".| following-sibling::list | following-sibling::sublist | following-sibling::sub_sublist | following-sibling::sub_sub_sublist"/>
    </done>
    </xsl:if>
    </xsl:if>
    </xsl:if>
    </xsl:if>
</xsl:template>
</xsl:stylesheet>

Observed out put
-----------------
....
 <subsec>
                  <done>
            <list>1. First level nunmbered list</list>
            <list>2. First level nunmbered list</list>
            <sublist>(a) Second level nunmbered list</sublist>
            <sublist>(b) Second level nunmbered list</sublist>
            <list>3. First level nunmbered list</list>
            <sublist>I) Second level nunmbered list</sublist>
            <sub_sublist>A. Third level nunmbered list</sub_sublist>
            <sub_sublist>B. Third level nunmbered list</sub_sublist>
            <sublist>II) Second level nunmbered list</sublist>
            <sublist>III) Seconcd level nunmbered list</sublist>
            <list>4. First level nunmbered list</list>
            <list>5. First level nunmbered list</list>
            <list>6. First level nunmbered list</list>
            <sublist>I) Second level nunmbered list</sublist>
            <sublist>II) Second level nunmbered list</sublist>
            <list>7. First level nunmbered list</list>
            <sublist>I) Second level nunmbered list</sublist>
            <sub_sublist>A. Third level nunmbered list</sub_sublist>
            <sub_sublist>B. Third level nunmbered list</sub_sublist>
            <sublist>I) Second level nunmbered list</sublist>
            <sublist>II) Second level nunmbered list</sublist>
            <list>8. First level nunmbered list</list>
         </done>

As you see the above XSL transforms all the lists grouping under <done>, but I would like to group each and every sublist under a element. I tried uising 'following-sibilings' and 'mode' method but it results repetations and I was expecting as follows.


.........
 <subsec>
       <done>
            <list>1. First level nunmbered list</list>
            <list>2. First level nunmbered list</list>

            <root_sublist>
            <sublist>(a) Second level nunmbered list</sublist>
            <sublist>(b) Second level nunmbered list</sublist>
            </root_sublist>

            <list>3. First level nunmbered list</list>

            <root_sublist>
            <sublist>I) Second level nunmbered list</sublist>

            <root_sub_sublist>
            <sub_sublist>A. Third level nunmbered list</sub_sublist>
            <sub_sublist>B. Third level nunmbered list</sub_sublist>
            </root_sub_sublist>

            <sublist>II) Second level nunmbered list</sublist>
            <sublist>III) Seconcd level nunmbered list</sublist>
            </root_sublist>

            <list>4. First level nunmbered list</list>
            <list>5. First level nunmbered list</list>
            <list>6. First level nunmbered list</list>

            <root_sublist>
            <sublist>I) Second level nunmbered list</sublist>
            <sublist>II) Second level nunmbered list</sublist>
            </root_sublist>
            <list>7. First level nunmbered list</list>
            |
        |
        |
        |
        |
         </done>
.......



I would greatly appreciate any help provided.

Thanks & Regards,
- ROCXY


__________________
Thanks,
Rocxy.





Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I list multiple items on 1 job? bamajog Access 3 April 19th, 2007 03:27 PM
grouping multiple xml files in one file bcogney XSLT 3 April 21st, 2006 03:58 AM
Grouping multiple paragraph styles under 1 parent ROCXY XML 0 January 4th, 2006 09:42 AM
Grouping List chemi XSLT 1 October 20th, 2005 09:36 AM
add multiple list to textbox stoneman Access 1 November 3rd, 2003 01:10 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.