xsl-list
[Top] [All Lists]

Re: [xsl] Grouping Problem in HTML Hedear Tag

2006-06-30 01:53:31


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

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

<Prev in Thread] Current Thread [Next in Thread>