[xsl] Re: Grouping Problem in Hedear Tag

Subject: [xsl] Re: Grouping Problem in Hedear Tag
From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx>
Date: Thu, 29 Jun 2006 12:43:53 +0530
Hi Byomkesh,
  I'll think about your question, and let you know.

Its wise not to address question to a specific person on the list, as
other people who might know the answer will generally not respond.

Regards,
Mukul

On 6/29/06, Byomkesh <bkesh@xxxxxxxxxxxxxxx> wrote:
Dear Mukul,

I am so confused in Grouping style. I am new about apply Group. Some text
(next <h1> text) is missing in my output files. So Please Check my files....
My following Xml file is

XML File
------------

<html>
<body>
<div>
 <h1>Heading 1.</h1>
 <p>Some text here..</p>
 <p>Sahoo</p>
</div>
<div>
 <h2>Heading 2...</h2>
 <p>text here....</p>
<!-- If i am creat another <h2> text here, its not converting properly. -->

</div>
<div>
<h3>Heading 3.....</h3>
 <p>Some text here......</p>
</div>
<div>
 <h1>Again Heading 1.</h1>
 <p>Some text here..</p>
 <p>Introduction to Wi-Fi</p>
</div>
<div>
 <h2>Again Heading 2...</h2>
 <p>text here....</p>
 <p>History and Basics</p>
</div>
<div>
<h3>Again Heading 3.....</h3>
 <p>Some text here......</p>
</div>
</body>
</html>

and My XSL file
--------------------

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
version="2.0">

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

<xsl:template match="body">
  <document>
      <xsl:for-each-group select="*" group-starting-with="h1">
         <section1>
   <title><xsl:value-of select="current-group()[1]/h1" /></title>
 <xsl:choose>
  <xsl:when test="p">
  <xsl:apply-templates select="p"/>
  </xsl:when>

 </xsl:choose>
   <xsl:for-each-group select="current-group()[position() &gt; 1]"
group-starting-with="h2">
                 <section2>
   <title><xsl:value-of select="current-group()[1]/h2"/></title>
 <xsl:choose>
  <xsl:when test="p">
  <xsl:apply-templates select="p"/>
  </xsl:when>

 </xsl:choose>
   <xsl:for-each-group select="current-group()[position() &gt; 1]"
group-starting-with="h3">
         <section3>
         <title><xsl:value-of select="current-group()[1]/h3" /></title>
 <xsl:choose>
  <xsl:when test="p">
  <xsl:apply-templates select="p"/>
  </xsl:when>

</xsl:choose>

         </section3>
                     </xsl:for-each-group>
 </section2>
             </xsl:for-each-group>
         </section1>
      </xsl:for-each-group>
  </document>
</xsl:template>

<xsl:template match="p">
<para>
<xsl:apply-templates/>
</para>
</xsl:template>

</xsl:stylesheet>

Now my out put ---------

<?xml version="1.0" encoding="UTF-8"?>
<document>
  <section1>
     <title>Heading 1.</title>
     <para>Some text here..</para>
     <para>Sahoo</para>
     <section2>
        <title>Heading 2...</title>
        <para>text here....</para>
        <section3>
           <title>Heading 3.....</title>
           <para>Some text here......</para>
        </section3>
     </section2>
  </section1>
<!-- Missing in Next <h1> text.. -->

</document>

Please suggest me, what is wrong.

Thanks and Regards

Byomkesh

Current Thread