Author: ks
Date: Wed Oct 3 20:12:57 2007
New Revision: 6348
Log:
- Implemented "plain headers -> nested sections" conversion with one template
for all header levels.
Modified:
experimental/Document/src/converters/xhtml_docbook.xsl
Modified: experimental/Document/src/converters/xhtml_docbook.xsl
==============================================================================
--- experimental/Document/src/converters/xhtml_docbook.xsl [iso-8859-1]
(original)
+++ experimental/Document/src/converters/xhtml_docbook.xsl [iso-8859-1] Wed Oct
3 20:12:57 2007
@@ -5,7 +5,8 @@
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns:saxon="http://icl.com/saxon"
xmlns:set="http://exslt.org/sets"
- extension-element-prefixes="set"
+ xmlns:dyn="http://exslt.org/dynamic"
+ extension-element-prefixes="set saxon dyn"
exclude-result-prefixes="xsl fo html saxon">
<xsl:output method="xml" indent="no"/>
@@ -32,82 +33,56 @@
<title><xsl:value-of select='.'/></title>
</xsl:template>
-<!-- This template converts each HTML file encountered into a DocBook
- section. For a title, it selects the first h1 element
+<!-- HTML Body -->
<xsl:template match="html:body">
- <section>
- <xsl:if test="$filename != ''">
- <xsl:attribute name="id">
- <xsl:value-of select="$prefix"/>
- <xsl:text>_</xsl:text>
- <xsl:value-of select="translate($filename,' ()','__')"/>
- </xsl:attribute>
- </xsl:if>
- <title>
- <xsl:value-of select=".//html:h1[1]
- |.//html:h2[1]
- |.//html:h3[1]"/>
- </title>
- <xsl:apply-templates select="*"/>
- </section>
-</xsl:template>
--->
-
-<xsl:template match="html:body">
+ <!-- Render everything before the first header -->
<xsl:apply-templates
select='set:leading(following-sibling::*,following-sibling::html:h1)'/>
+ <!-- Render level 1 headers -->
<xsl:apply-templates select="html:h1"/>
</xsl:template>
-<xsl:template match="html:h1">
+<xsl:template match="html:h1|html:h2|html:h3|html:h4|html:h5|html:h6">
<section>
<title>
<xsl:apply-templates/>
</title>
- <xsl:apply-templates
select='set:leading(following-sibling::*,following-sibling::html:h1|following-sibling::html:h2)'/>
- <xsl:apply-templates
select='set:leading(following-sibling::html:h1|following-sibling::html:h2,following-sibling::html:h1)'/>
+
+ <xsl:variable name='level' select="number(substring-after(name(),'h'))"/>
+ <!-- Make a string like
"following-sibling::html:h2|following-sibling::html:h1" (for level=2)-->
+ <xsl:variable name='fheaders'>
+ <xsl:call-template name = "make_header_string">
+ <xsl:with-param name="num" select="$level"/>
+ </xsl:call-template>
+ </xsl:variable>
+ <!-- Make a string like
"following-sibling::html:h3|following-sibling::html:h2|following-sibling::html:h1"
(for level=2)-->
+ <xsl:variable name='fheaders1'>
+ <xsl:call-template name = "make_header_string">
+ <xsl:with-param name="num" select="$level + 1"/>
+ </xsl:call-template>
+ </xsl:variable>
+
+ <!-- Render all the following-sibling elements before headers -->
+ <xsl:apply-templates
select='set:leading(following-sibling::*,dyn:evaluate($fheaders1))'/>
+
+ <!-- Render the following-sibling next level headers -->
+ <xsl:apply-templates
select="set:leading(dyn:evaluate($fheaders1),dyn:evaluate($fheaders))"/>
+
</section>
</xsl:template>
-<xsl:template match="html:h2">
- <section>
- <title>
- <xsl:apply-templates/>
- </title>
- <xsl:apply-templates
select='set:leading(following-sibling::*,following-sibling::html:h1|following-sibling::html:h2)'/>
- </section>
-</xsl:template>
-
-<!-- This template matches on all HTML header items and makes them into
- bridgeheads. It attempts to assign an ID to each bridgehead by looking
- for a named anchor as a child of the header or as the immediate preceding
- or following sibling
-<xsl:template match="html:h1
- |html:h2
- |html:h3
- |html:h4
- |html:h5
- |html:h6">
- <bridgehead>
- <xsl:choose>
- <xsl:when test="count(html:a/@name)">
- <xsl:attribute name="id">
- <xsl:value-of select="html:a/@name"/>
- </xsl:attribute>
- </xsl:when>
- <xsl:when test="preceding-sibling::* = preceding-sibling::html:[EMAIL
PROTECTED] != '']">
- <xsl:attribute name="id">
- <xsl:value-of select="concat($prefix,preceding-sibling::html:a[1]/@name)"/>
- </xsl:attribute>
- </xsl:when>
- <xsl:when test="following-sibling::* = following-sibling::html:[EMAIL
PROTECTED] != '']">
- <xsl:attribute name="id">
- <xsl:value-of select="concat($prefix,following-sibling::html:a[1]/@name)"/>
- </xsl:attribute>
- </xsl:when>
- </xsl:choose>
- <xsl:apply-templates/>
- </bridgehead>
-</xsl:template>-->
+<xsl:template name="make_header_string">
+ <xsl:param name="num"/>
+ <xsl:if test="not($num = 0)">
+ <xsl:text>following-sibling::html:h</xsl:text>
+ <xsl:value-of select="$num"/>
+ <xsl:if test="not($num = 1)">
+ <xsl:text>|</xsl:text>
+ </xsl:if>
+ <xsl:call-template name = "make_header_string">
+ <xsl:with-param name="num" select="$num - 1" />
+ </xsl:call-template>
+ </xsl:if>
+</xsl:template>
<!-- These templates perform one-to-one conversions of HTML elements into
DocBook elements -->
--
svn-components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/svn-components