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

Re: How Handle Html Heading Tag using XSL

Subject: Re: How Handle Html Heading Tag using XSL
From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx>
Date: Wed, 28 Jun 2006 10:28:40 +0530
html heading 1
Hi Byomkesh,
  Since you are using XSLT 2.0, you must use xsl:for-each-group
instruction (as Michael explained). Following is the solution:

XML file:
<html>
<h1>Heading 1.</h1>
<p>Some text here..</p>
<h2>Heading 2...</h2>
<p>Some text here....</p>
<h3>Heading 3.....</h3>
<p>Some text here......</p>
<h1>Heading 1.......</h1>
<p>Some text here........</p>
</html>

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

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

<xsl:template match="/html">
  <document>
      <xsl:for-each-group select="*" group-starting-with="h1">
         <section1>
             <title><xsl:value-of select="current-group()[1]" /></title>
             <p><xsl:value-of select="current-group()[2]" /></p>
             <xsl:for-each-group select="current-group()[position()
&gt; 2]" group-starting-with="h2">
                 <section2>
                     <title><xsl:value-of select="current-group()[1]"
/></title>
                     <p><xsl:value-of select="current-group()[2]" /></p>
                     <xsl:for-each-group
select="current-group()[position() &gt; 2]" group-starting-with="h3">
	          <section3>
                            <title><xsl:value-of
select="current-group()[1]" /></title>
                            <p><xsl:value-of select="current-group()[2]" /></p>
	          </section3>
                     </xsl:for-each-group>
	  </section2>
             </xsl:for-each-group>
         </section1>
      </xsl:for-each-group>
  </document>
</xsl:template>

</xsl:stylesheet>

Output:
<?xml version="1.0" encoding="UTF-8"?>
<document>
  <section1>
     <title>Heading 1.</title>
     <p>Some text here..</p>
     <section2>
        <title>Heading 2...</title>
        <p>Some text here....</p>
        <section3>
           <title>Heading 3.....</title>
           <p>Some text here......</p>
        </section3>
     </section2>
  </section1>
  <section1>
     <title>Heading 1.......</title>
     <p>Some text here........</p>
  </section1>
</document>

Regards,
Mukul

On 6/27/06, Byomkesh <bkesh@xxxxxxxxxxxxxxx> wrote:
Thank you Mukul for the help!

I have one problem. How handle the html h1, h2, h3 etc., coding. I would
like to close </h1> tag before start in another <h1> tag.

Example...

Input file
---------

<h1>Heading 1</h1>
<p>Some text here</p>
<h2>Heading 2</h2>
<p>Some text here</p>
<h3>Heading 3</h3>
<p>Some text here</p>
<h1>Heading 1</h1>
<p>Some text here</p>

I want.....
--------

<section1>
<title>Heading 1</title>
<p>Some text here</p>
<section2><title>Heading 2</title>
<p>Some text here</p>
<section3><title>Heading 3</title>
<p>Some text here</p>
</section3></section2></section1>
<section1><title>Heading 1</title>
<p>Some text here</p>
.....
.....
.....

Thanks

Byomkesh

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-2007 All Rights Reserved.