Subject: Re: [xsl] Grouping Problem in HTML Header Tag From: "Mukul Gandhi" <gandhi.mukul@xxxxxxxxx> Date: Sun, 2 Jul 2006 00:03:52 +0530 |
I am sorry, but you are changing your input XML and the desired output every time, and not telling us the transformation rules completely. Its hard to write the stylesheet for requirements you haven't told us.
Also, I suggest please don't start a new thread every time you post. Please continue with the same thread, if you are discussing the same topic.
Regards, Mukul
Hi David,
Thanks you for suggestion. But ( <!-- If i am creat another <h2> text here, its not converting properly. -->) not convert in <section2>. This tag skipp only title.
This is my Input File ---------------------------
<?xml version="1.0" ?> <html> <body> <div> <h1>Chapter 1<br/>A Brief Overview"s of the Wireless World</h1> <p><b>Topics in this Chapter:</b></p> </div> <div> <h2>Introduction to Wi-Fi</h2> <p>Welcome to the world</p> <!-- Just concentrate Here --> <h2>Introduction Wi-Fi</h2> <p>Once gone through</p> </div> <div> <h2>The History and Basics of 802.11</h2> <p>The desire of people</p> </div> <div> <h3>IEEE Alphabet Soup</h3> <p>Understanding.</p> </div> <div> <h4>802.11b</h4> <p>For many years</p> </div> <div> <h4>802.11a</h4> <p>Although 802.11a</p> </div> <div> <h3>Ad-Hoc and Infrastructure Modes</h3> <!-- Just concentrate Here --> <h3>Ad-Hoc and Infrastructure</h3> <p>When architecting</p> </div> <div> <h4>Connecting to an Access Point</h4> <p>In order</p> <ul> <li>Unauthenticated and unassociated</li> <li>Authenticated and unassociated</li> </ul> </div> <div> <h5>SSID <i>Discovery</i></h5> <p>There are two.</p> </div> </body> </html>
I want output ------------------------------------------
<?xml version="1.0" encoding="UTF-8"?> <document> <body> <level id="ch1"><title>Chapter 1<br/>A Brief Overview"s of the Wireless World</title> <p><b>Topics in this Chapter:</b></p> <level id="ch1sec1"><title>Introduction to Wi-Fi</title> <p>Welcome to the world</p> </level> <!-- Just concentrate Here --> <level id="ch1sec2"><title>Introduction Wi-Fi</title> <p>Once gone through</p> </level> <level id="ch1sec3"><title>The History and Basics of 802.11</title> <p>The desire of people</p> <level id="ch1sec3.1"><title>IEEE Alphabet Soup</title> <p>Understanding.</p> <level id="ch1sec3.1.1"><title>802.11b</title> <p>For many years</p> </level> <level id="ch1sec3.1.2"><title>802.11a</title> <p>Although 802.11a</p> </level> </level> <level id="ch1sec3.2"><title>Ad-Hoc and Infrastructure Modes</title> </level> <!-- Just concentrate Here --> <level id="ch1sec3.3"><title>Ad-Hoc and Infrastructure</title> <p>When architecting</p> <level id="ch1sec3.3.1"><title>Connecting to an Access Point</title> <p>In order</p> <page.list> <item><label>1.</label><para>Unauthenticated and unassociated</para></item> <item><label>2.</label><para>Authenticated and unassociated</para></item> </page.list> <level id="ch1sec3.3.1.1"><title>SSID <i>Discovery</i></title> <p>There are two.</p> </level> </level> </level> </level> </level> </body> </document>
I did not understand How convert in nested elements. Is it possible?
Thanks
Byomkesh
Date: Fri, 30 Jun 2006 09:52:51 +0100 To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx From: David Carlisle <davidc@xxxxxxxxx> Subject: Re: [xsl] Grouping Problem in HTML Hedear Tag Message-Id: <200606300852.k5U8qpTV021178@xxxxxxxxxxxxxxxxxxx>
<!-- If i am creat another <h2> text here, its not converting properly. -->
Normally when converting from html-style headings to nested section elements you need to use a grouping construct as html headings are not nested, a section just goes from one <h..> element as far as the next a <h...> with the same or lower number.
However in your case (initially) you _do_ have nested elements (divs) marking the section structure, so in that case you don't really need to use any grouping at all, just a template that changes (say) a div containing an h1 to a section1 containing a title
<xsl:template match="div[h1]"> <section1> <xsl/apply-templates/> </section1> </xsl:template>
(and same for h2 section2 etc).
then:
<xsl:template match="h1|h2|h3|h4|h5"> <title> <xsl/apply-templates/> </title> </xsl:template>
However if I understand your comment you then want to add multiple h2 titles _within the same div) if you do that then you would need to go back to using a grouping construct but before suggesting code I think you'd need a fulll description of your input format, which sections in the input are surrounded by div and which are not?
David
If all your sections are in divs you just need something like
<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:apply-templates/> </document> </xsl:template>
<xsl:template match="div[h1|h2|h3|h4|h5]"> <xsl:element name="section{substring(name(*[1]),2)}"> <xsl:apply-templates/> </xsl:element> </xsl:template>
<xsl:template match="h1|h2|h3|h4|h5"> <title> <xsl:apply-templates/> </title> </xsl:template>
<xsl:template match="p"> <para> <xsl:apply-templates/> </para> </xsl:template>
</xsl:stylesheet>
which produces:
$ saxon8 gph.xml gph2.xsl <?xml version="1.0" encoding="UTF-8"?> <document> <section1> <title>Heading 1.</title> <para>Some text here..</para> <para>Sahoo</para> </section1> <section2> <title>Heading 2...</title> <para>text here....</para>
</section2> <section3> <title>Heading 3.....</title> <para>Some text here......</para> </section3> <section1> <title>Again Heading 1.</title> <para>Some text here..</para> <para>Introduction to Wi-Fi</para> </section1> <section2> <title>Again Heading 2...</title> <para>text here....</para> <para>History and Basics</para> </section2> <section3> <title>Again Heading 3.....</title> <para>Some text here......</para> </section3> </document>
Current Thread |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] Grouping Problem in HTML , Byomkesh | Thread | Re: [xsl] Grouping Problem in HTML , David Carlisle |
[xsl] XSL-List Guidelines, Mulberry Technologie | Date | [xsl] Extracting XPath stuff for an, James Steward |
Month |