From 1ef56087def2a8a4e8f1a06246aa14b4206c3393 Mon Sep 17 00:00:00 2001 From: Norman Walsh <ndw@nwalsh.com> Date: Tue, 24 Apr 2001 12:54:10 +0000 Subject: [PATCH] Feature request 416507: added chunk.sections and chunk.first.sections to provide greater chunking flexibility --- xsl/html/chunk-common.xsl | 286 +++++++++++++++++++++++++++++++++----- 1 file changed, 249 insertions(+), 37 deletions(-) diff --git a/xsl/html/chunk-common.xsl b/xsl/html/chunk-common.xsl index 95b5d720e..28b7afba8 100644 --- a/xsl/html/chunk-common.xsl +++ b/xsl/html/chunk-common.xsl @@ -10,7 +10,25 @@ indent="no"/> <xsl:param name="html.ext" select="'.html'"/> +<doc:param name="html.ext" xmlns=""> +<refpurpose>Extension for chunked files</refpurpose> +<refdescription> +<para>The extension identified by <parameter>html.ext</parameter> will +be used as the filename extension for chunks created by this stylesheet. +</para> +</refdescription> +</doc:param> + <xsl:param name="root.filename" select="'index'"/> +<doc:param name="root.filename" xmlns=""> +<refpurpose>Filename for the root chunk</refpurpose> +<refdescription> +<para>The <parameter>root.filename</parameter> is the base filename for +the chunk created for the root of each document processed. +</para> +</refdescription> +</doc:param> + <xsl:param name="base.dir" select="''"/> <doc:param name="base.dir" xmlns=""> <refpurpose>Output directory for chunks</refpurpose> @@ -21,6 +39,29 @@ is system dependent.)</para> </refdescription> </doc:param> +<xsl:param name="chunk.sections" select="'1'"/> +<doc:param name="chunk.sections" xmlns=""> +<refpurpose>Create chunks for top-level sections in components?</refpurpose> +<refdescription> +<para>If non-zero, chunks will be created for top-level +<sgmltag>sect1</sgmltag> and <sgmltag>section</sgmltag> elements in +each component. +</para> +</refdescription> +</doc:param> + +<xsl:param name="chunk.first.sections" select="'0'"/> +<doc:param name="chunk.first.sections" xmlns=""> +<refpurpose>Create a chunk for the first top-level section in each component?</refpurpose> +<refdescription> +<para>If non-zero, a chunk will be created for the first top-level +<sgmltag>sect1</sgmltag> or <sgmltag>section</sgmltag> elements in +each component. Otherwise, that section will be part of the chunk for +its parent. +</para> +</refdescription> +</doc:param> + <!-- ==================================================================== --> <!-- What's a chunk? @@ -48,11 +89,19 @@ is system dependent.)</para> <!-- returns 1 if $node is a chunk --> <xsl:choose> - <xsl:when test="name($node)='sect1' - and count($node/preceding-sibling::sect1) > 0">1</xsl:when> - <xsl:when test="name($node)='section' - and count($node/parent::section) = 0 - and count($node/preceding-sibling::section) > 0">1</xsl:when> + <xsl:when test="$chunk.sections != 0 + and name($node)='sect1' + and ($chunk.first.sections != 0 + or count($node/preceding-sibling::sect1) > 0)"> + <xsl:text>1</xsl:text> + </xsl:when> + <xsl:when test="$chunk.sections != 0 + and name($node)='section' + and ($chunk.first.sections != 0 + or (count($node/parent::section) = 0 + and count($node/preceding-sibling::section)))>0"> + <xsl:text>1</xsl:text> + </xsl:when> <xsl:when test="name($node)='preface'">1</xsl:when> <xsl:when test="name($node)='chapter'">1</xsl:when> <xsl:when test="name($node)='appendix'">1</xsl:when> @@ -591,8 +640,60 @@ is system dependent.)</para> <!-- ==================================================================== --> <xsl:template name="process-chunk-element"> - <xsl:variable name="root" select="count(parent::*) > 0"/> + <xsl:choose> + <xsl:when test="$chunk.sections = 0"> + <xsl:call-template name="chunk-no-sections"/> + </xsl:when> + <xsl:when test="$chunk.first.sections = 0"> + <xsl:call-template name="chunk-first-section-with-parent"/> + </xsl:when> + <xsl:otherwise> + <xsl:call-template name="chunk-all-top-level-sections"/> + </xsl:otherwise> + </xsl:choose> +</xsl:template> + +<xsl:template name="process-chunk"> + <xsl:param name="prev" select="."/> + <xsl:param name="next" select="."/> + <xsl:variable name="ischunk"> + <xsl:call-template name="chunk"/> + </xsl:variable> + + <xsl:variable name="chunkfn"> + <xsl:if test="$ischunk='1'"> + <xsl:apply-templates mode="chunk-filename" select="."/> + </xsl:if> + </xsl:variable> + + <xsl:if test="$ischunk='0'"> + <xsl:message> + <xsl:text>Error </xsl:text> + <xsl:value-of select="name(.)"/> + <xsl:text> is not a chunk!</xsl:text> + </xsl:message> + </xsl:if> + + <xsl:variable name="filename"> + <xsl:call-template name="make-relative-filename"> + <xsl:with-param name="base.dir" select="$base.dir"/> + <xsl:with-param name="base.name" select="$chunkfn"/> + </xsl:call-template> + </xsl:variable> + + <xsl:call-template name="write.chunk"> + <xsl:with-param name="filename" select="$filename"/> + <xsl:with-param name="content"> + <xsl:call-template name="chunk-element-content"> + <xsl:with-param name="prev" select="$prev"/> + <xsl:with-param name="next" select="$next"/> + </xsl:call-template> + </xsl:with-param> + </xsl:call-template> +</xsl:template> + +<xsl:template name="chunk-first-section-with-parent"> <xsl:variable name="prev" select="(preceding::book[1] |preceding::preface[1] @@ -651,39 +752,131 @@ is system dependent.)</para> |descendant::sect1[2] |descendant::section[name(parent::*) != 'section'][2])[1]"/> - <xsl:variable name="ischunk"> - <xsl:call-template name="chunk"/> - </xsl:variable> + <xsl:call-template name="process-chunk"> + <xsl:with-param name="prev" select="$prev"/> + <xsl:with-param name="next" select="$next"/> + </xsl:call-template> +</xsl:template> - <xsl:variable name="chunkfn"> - <xsl:if test="$ischunk='1'"> - <xsl:apply-templates mode="chunk-filename" select="."/> - </xsl:if> - </xsl:variable> +<xsl:template name="chunk-all-top-level-sections"> + <xsl:variable name="prev" + select="(preceding::book[1] + |preceding::preface[1] + |preceding::chapter[1] + |preceding::appendix[1] + |preceding::part[1] + |preceding::reference[1] + |preceding::refentry[1] + |preceding::colophon[1] + |preceding::sect1[1] + |preceding::section[name(parent::*) != 'section'][1] + |preceding::article[1] + |preceding::bibliography[1] + |preceding::glossary[1] + |preceding::index[1] + |preceding::setindex[1] + |ancestor::set + |ancestor::book[1] + |ancestor::preface[1] + |ancestor::chapter[1] + |ancestor::appendix[1] + |ancestor::part[1] + |ancestor::reference[1] + |ancestor::article[1])[last()]"/> - <xsl:if test="$ischunk='0'"> - <xsl:message> - <xsl:text>Error </xsl:text> - <xsl:value-of select="name(.)"/> - <xsl:text> is not a chunk!</xsl:text> - </xsl:message> - </xsl:if> + <xsl:variable name="next" + select="(following::book[1] + |following::preface[1] + |following::chapter[1] + |following::appendix[1] + |following::part[1] + |following::reference[1] + |following::refentry[1] + |following::colophon[1] + |following::sect1[1] + |following::section[name(parent::*) != 'section'][1] + |following::bibliography[1] + |following::glossary[1] + |following::index[1] + |following::article[1] + |following::setindex[1] + |descendant::book[1] + |descendant::preface[1] + |descendant::chapter[1] + |descendant::appendix[1] + |descendant::article[1] + |descendant::bibliography[1] + |descendant::glossary[1] + |descendant::index[1] + |descendant::colophon[1] + |descendant::setindex[1] + |descendant::part[1] + |descendant::reference[1] + |descendant::refentry[1] + |descendant::sect1[1] + |descendant::section[name(parent::*) != 'section'][1])[1]"/> - <xsl:variable name="filename"> - <xsl:call-template name="make-relative-filename"> - <xsl:with-param name="base.dir" select="$base.dir"/> - <xsl:with-param name="base.name" select="$chunkfn"/> - </xsl:call-template> - </xsl:variable> + <xsl:call-template name="process-chunk"> + <xsl:with-param name="prev" select="$prev"/> + <xsl:with-param name="next" select="$next"/> + </xsl:call-template> +</xsl:template> - <xsl:call-template name="write.chunk"> - <xsl:with-param name="filename" select="$filename"/> - <xsl:with-param name="content"> - <xsl:call-template name="chunk-element-content"> - <xsl:with-param name="prev" select="$prev"/> - <xsl:with-param name="next" select="$next"/> - </xsl:call-template> - </xsl:with-param> +<xsl:template name="chunk-no-sections"> + <xsl:variable name="prev" + select="(preceding::book[1] + |preceding::preface[1] + |preceding::chapter[1] + |preceding::appendix[1] + |preceding::part[1] + |preceding::reference[1] + |preceding::refentry[1] + |preceding::colophon[1] + |preceding::article[1] + |preceding::bibliography[1] + |preceding::glossary[1] + |preceding::index[1] + |preceding::setindex[1] + |ancestor::set + |ancestor::book[1] + |ancestor::preface[1] + |ancestor::chapter[1] + |ancestor::appendix[1] + |ancestor::part[1] + |ancestor::reference[1] + |ancestor::article[1])[last()]"/> + + <xsl:variable name="next" + select="(following::book[1] + |following::preface[1] + |following::chapter[1] + |following::appendix[1] + |following::part[1] + |following::reference[1] + |following::refentry[1] + |following::colophon[1] + |following::bibliography[1] + |following::glossary[1] + |following::index[1] + |following::article[1] + |following::setindex[1] + |descendant::book[1] + |descendant::preface[1] + |descendant::chapter[1] + |descendant::appendix[1] + |descendant::article[1] + |descendant::bibliography[1] + |descendant::glossary[1] + |descendant::index[1] + |descendant::colophon[1] + |descendant::setindex[1] + |descendant::part[1] + |descendant::reference[1] + |descendant::refentry[1])[1]"/> + + <xsl:call-template name="process-chunk"> + <xsl:with-param name="prev" select="$prev"/> + <xsl:with-param name="next" select="$next"/> </xsl:call-template> </xsl:template> @@ -750,14 +943,33 @@ is system dependent.)</para> <xsl:template match="set|book|part|preface|chapter|appendix |article |reference|refentry - |sect1[position()>1] - |section[position()>1 and name(parent::*) != 'section'] |book/glossary|article/glossary |book/bibliography|article/bibliography |colophon"> <xsl:call-template name="process-chunk-element"/> </xsl:template> +<xsl:template match="sect1|section[local-name(parent::*) != 'section']"> + <xsl:choose> + <xsl:when test="$chunk.sections = 0"> + <xsl:apply-imports/> + </xsl:when> + <xsl:when test="$chunk.first.sections = 0"> + <xsl:choose> + <xsl:when test="position() > 1"> + <xsl:call-template name="process-chunk-element"/> + </xsl:when> + <xsl:otherwise> + <xsl:apply-imports/> + </xsl:otherwise> + </xsl:choose> + </xsl:when> + <xsl:otherwise> + <xsl:call-template name="process-chunk-element"/> + </xsl:otherwise> + </xsl:choose> +</xsl:template> + <xsl:template match="setindex |book/index |article/index"> -- 2.40.0