xsl-list
[Top] [All Lists]

Re: [xsl] Multiple for-each-group in a single template

2008-11-20 06:08:43
Your XML is not wel formed.  if you could send back the XML that is
properly closes ( see the h1, h2, and p class= "heading.. ) is not
closed.
its hard to device a solution with out knowing the correct input.

<body>
       <p class="heading-1">Heading 1</h1>
               <p>para 1</p>
               <p class="box">para 2</p>
               <p class="box">para 3</p>
               <p>para 4</p>
       <p class="heading-2">Heading 2</h2>
               <p>para 1</p>
               <p class="exercise">para 2</p>
               <p class="exercise">para 3</p>
               <p>para 4</p>
</body>

Vasu

On Thu, Nov 20, 2008 at 10:55 AM, V.Ramkumar
<v(_dot_)ramkumar(_at_)macmillansolutions(_dot_)com> wrote:


Regards,
Ramkumar
Software - Digital Services Division,
Macmillan India Ltd.- Chennai 600 018.


-----Original Message-----
From: V.Ramkumar [mailto:v(_dot_)ramkumar(_at_)macmillansolutions(_dot_)com]
Sent: Thursday, November 20, 2008 4:20 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Multiple for-each-group in a single template

Hi List,

I am getting duplicate when use multiple for-each-group in a single template
(based on single parent). Please find mistakes in my xslt.

Input:
<body>
       <p class="heading-1">Heading 1</h1>
               <p>para 1</p>
               <p class="box">para 2</p>
               <p class="box">para 3</p>
               <p>para 4</p>
       <p class="heading-2">Heading 2</h2>
               <p>para 1</p>
               <p class="exercise">para 2</p>
               <p class="exercise">para 3</p>
               <p>para 4</p>
</body>

Exp.Output:

<body>
       <section title="Heading-1">
               <p>para 1</p>
               <box>
                       <p>para 2</p>
                       <p>para 3</p>
               </box>
                       <p>para 4</p>
       </section>
       <section title="Heading-2">
               <p>para 1</p>
               <excecise>
                       <p>para 2</p>
                       <p>para 3</p>
               </excecise>
               <p>para 4</p>
       </section>
</body>

My XSLT: (sample)
       <xsl:template match="body">
       <body>
                       <xsl:for-each-group select="*"
group-adjacent="string(self::p/@class[contains(.,'box')])">
                       <xsl:choose>
                               <xsl:when
test="self::p/@class[contains(.,'box')]">
                                       <box>
                                               <xsl:apply-templates
select="current-group()"/>
                                       </box>
                               </xsl:when>
                               <xsl:otherwise>
                                       <xsl:apply-templates
select="current-group()"/>
                               </xsl:otherwise>
                       </xsl:choose>
                       </xsl:for-each-group>
               <xsl:for-each-group select="*"
group-adjacent="string(self::p/@class[contains(.,'exercise')])">
                       <xsl:choose>
                               <xsl:when
test="self::p/@class[contains(.,'exercise')]">
                                       <exercise>
                                               <xsl:apply-templates
select="current-group()"/>
                                       </exercise>
                               </xsl:when>
                               <xsl:otherwise>
                                       <xsl:apply-templates
select="current-group()"/>
                               </xsl:otherwise>
                       </xsl:choose>
               </xsl:for-each-group>
......like wise section and all

       </body>

Regards,
Ramkumar


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


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





-- 
Vasu Chakkera
Numerical Algorithms Group Ltd.
Oxford
www.vasucv.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>
--~--