Section numbering using xmerl:export

Mikael Karlsson mikael.karlsson@REDACTED
Thu Aug 29 19:14:20 CEST 2002


Actually this seems to work fine in my documents,
but maybe I did not understand your point. 
I actually check the section parents in the "title" element.
/Mikael

7> test_xhtml:test().
Parents [{article,1}]
Parents [{section,4},{article,1}]
Parents [{section,5},{section,4},{article,1}]
Parents [{section,7},{section,4},{article,1}]
Parents [{section,5},{section,7},{section,4},{article,1}]
Parents [{section,7},{section,7},{section,4},{article,1}]
Parents [{section,6},{article,1}]
Parents [{section,5},{section,6},{article,1}]
Parents [{section,7},{section,6},{article,1}]
Parents [{section,5},{section,7},{section,6},{article,1}]


Input:
--------------------------
<?xml version="1.0"?>
<!DOCTYPE article PUBLIC "-//OASIS//DTD Simplified DocBook XML V4.1.2.5//EN"
"http://www.oasis-open.org/docbook/xml/simple/4.1.2.5/sdocbook.dtd" >
<article>
<title>A Test Document</title>
<section><title>Section 1</title>
 <para>This is para 1.</para>
<section><title>Section 1.1</title>
 <para>This is para 2 <emphasis>with emphasis</emphasis> in it.</para>
 <para>This is para 3.</para>
</section>
<section><title>Section 1.2</title>
 <para id="p4">This is para 4.</para>
<section><title>Section 1.2.1</title>
</section>
<section><title>Section 1.2.2</title>
</section>
</section>
 <para id="p5">This is para 5.</para>
</section>
<section><title>Section 2</title>
 <para>This is para 6.</para>
<section><title>Section 2.1</title>
</section>
<section><title>Section 2.2</title>
 <para>This is para 7.</para>
<section><title>Section 2.2.1</title>
</section>
</section>
 <para>This is para 8.</para>
 <para>This is para 9.</para>
</section>
</article>
---------------------------------------
Output:
<?xml version="1.0"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"DTD/xhtml1-strict.dtd">
<html><head></head>
<body>
<h1>A Test Document</h1>
<h2>1   Section 1</h2>
 <p>This is para 1.</p>
<h3>1.1  Section 1.1</h3>
 <p>This is para 2 <em>with emphasis</em> in it.</p>
 <p>This is para 3.</p>
<h3>1.2  Section 1.2</h3>
 <p id="p4">This is para 4.</p>
<h4>1.2.1 Section 1.2.1</h4>
<h4>1.2.2 Section 1.2.2</h4>
 <p id="p5">This is para 5.</p>
<h2>2   Section 2</h2>
 <p>This is para 6.</p>
<h3>2.1  Section 2.1</h3>
<h3>2.2  Section 2.2</h3>
 <p>This is para 7.</p>
<h4>2.2.1 Section 2.2.1</h4>
 <p>This is para 8.</p>
 <p>This is para 9.</p>
</body></html>
------------------------------

torsdag 29 augusti 2002 18:07 skrev Ulf Wiger:
> nOn Thu, 29 Aug 2002, Mikael Karlsson wrote:
> >Hi,
> >
> >I am trying to export a Simple Docbook xml to xhtml using the
> >export function in xmlerl. I wan't to have section numbering in
> >the 3 top levels and after some testing I could use the
> >ParentTagPosition from the [{ParentTag, ParentTagPosition}]
> >argument. (See code below.)
> >
> >The top section gets position 4, next top section pos 6,
> >subsections get pos 5, 7, etc.. .
> >
> >Now, is this just a lucky coincidence or is it something I can
> >expect for any document?
>
> Hmm, sounds risky. The position number enumerates the child
> elements in order, but unless you can guarantee that your
> chapter elements will never contain a non-chapter sibling, that
> particular scheme will not work.
>
> A typical scheme might be:
>
>  <section>
>    <para>... </para>
>    <section>
>      <para> ... </para>
>      ...
>      <section>
>    ...
>  </section>
>
> In this case it won't work to look at the position number,
> because it will be e.g.
>
>   {section, 1}, [
>      {para, 1},
>      {section, 2}, [
>         {para, 1},
>         {section, 2} | ...]}]
>   ]}
>
> Maybe this doesn't happen in your Simple DocBook...?
>
> One idea would be to modify the export concept to do something
> similar to xmerl_xpath. I had thought about doing this to make
> XSL-type operations possible via the export API. The trick used
> by xmerl_xpath is to put the full parent element in the parents
> list instead of just the {Tag, Position} indicator.
>
> This might seem expensive from a memory consumption point of
> view, but it is in fact just a pointer to the element behind the
> scenes. This would allow the tag function to freely inspect its
> parent or its siblings. In your case, you could go via the parent
> element and look at the preceding siblings, counting the
> occurences of 'section' elements.
>
> If this appeals to the rest of you, I could prototype such a
> modification. I don't know how much of an issue backwards
> compatibility is for xmerl...?
>
> /Uffe




More information about the erlang-questions mailing list