From: Norman W. <nw...@us...> - 2001-04-24 12:54:13
|
Update of /cvsroot/docbook/xsl/html In directory usw-pr-cvs1:/tmp/cvs-serv23920 Modified Files: chunk-common.xsl Log Message: Feature request 416507: added chunk.sections and chunk.first.sections to provide greater chunking flexibility Index: chunk-common.xsl =================================================================== RCS file: /cvsroot/docbook/xsl/html/chunk-common.xsl,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -r1.4 -r1.5 *** chunk-common.xsl 2001/04/15 21:12:34 1.4 --- chunk-common.xsl 2001/04/24 12:54:10 1.5 *************** *** 11,15 **** --- 11,33 ---- <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=""> *************** *** 22,25 **** --- 40,66 ---- </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? *************** *** 49,57 **** <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="name($node)='preface'">1</xsl:when> <xsl:when test="name($node)='chapter'">1</xsl:when> --- 90,106 ---- <xsl:choose> ! <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> *************** *** 592,597 **** <xsl:template name="process-chunk-element"> ! <xsl:variable name="root" select="count(parent::*) > 0"/> <xsl:variable name="prev" select="(preceding::book[1] --- 641,698 ---- <xsl:template name="process-chunk-element"> ! <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] *************** *** 652,688 **** |descendant::section[name(parent::*) != 'section'][2])[1]"/> ! <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> --- 753,881 ---- |descendant::section[name(parent::*) != 'section'][2])[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> ! <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: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: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: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> *************** *** 751,760 **** |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> --- 944,972 ---- |article |reference|refentry |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> |