Section numbering using xmerl:export
Ulf Wiger
etxuwig@REDACTED
Thu Aug 29 18:07:49 CEST 2002
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
--
Ulf Wiger, Senior Specialist,
/ / / Architecture & Design of Carrier-Class Software
/ / / Strategic Product & System Management
/ / / Ericsson Telecom AB, ATM Multiservice Networks
More information about the erlang-questions
mailing list