This is the mail archive of the
docbook@lists.oasis-open.org
mailing list for the DocBook project.
manual chunking with my chunk-manual.xsl
- From: Janning Vygen <vygen at gmx dot de>
- To: docbook at lists dot oasis-open dot org
- Date: Fri, 06 Sep 2002 16:57:10 +0200
- Subject: DOCBOOK: manual chunking with my chunk-manual.xsl
- Organization: Planwerk 6 /websolutions
Hi,
thanks to norm who wrote this beatiful chunkfast.xsl "just in time".
I am writing a customization which can give docbook authors the
possibility to chunk section manual by including a <?dbhtml
Procession instructions and i was just thinking about these really
hairy XPath expression in chunk.xsl about finding next and prev...
i was wondering how easy it was to write this customization after
understanding how things work together. This code is poorly tested
because i just want to ask if i am moving in the right direction. So
heres my module, but it only works with norms
http://nwalsh.com/chunk.xsl and http://nwalsh.com/chunkfast.xsl
posted earlier today and is only tested with 1.53.0 and libxslt 1.20
What it does is just modifying the template named "chunk" which
determines if a node is a chunk or not. To check it out it looks for
PIs and combines the result of examaning the PIs with the parameters
$chunk.section.depth and $chunk.first.sections
Any comments are very appreciated.
so heres my code. (i don't know if it is allowed to include
attachments).
kind regards,
janning
------ chunk-manual.xsl ------
<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<!--
2002, written by vygen@planwerk6.de,
1) you can decide via Processing Instruction
if you want to chunk the childs of the parent node of the PI
2) you can override the value of chunk.first.sections via PI
Put PIs like this into your chapter, section, sect1, sect2 ...
<?dbhtml chunk-childs="1" chunk-first-sections="0"?>
chunk-first-sections is inherited by all subsequent childs if not
changed again by another PI
chunk-childs affects only the childs of the parent node of the PI
(put your PI _into_ a chapter to chunk the sections inside this
chapter
you can only decide to
- chunk all childs but not the first
- chunk all child including the first
- chunk no childs
NO WARRENTY, most of the code is copyright by norm walsh, i guess
the few other characters can be used as you'd like :-)
-->
<xsl:import href="chunkfast.xsl"/>
<xsl:template name="dbhtml-chunk-childs">
<xsl:param name="pis" select="./processing-instruction('dbhtml')"/>
<xsl:call-template name="dbhtml-attribute">
<xsl:with-param name="pis" select="$pis"/>
<xsl:with-param name="attribute">chunk-childs</xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template name="dbhtml-chunk-first-sections">
<xsl:param name="pis" select="./processing-instruction('dbhtml')"/>
<xsl:call-template name="dbhtml-attribute">
<xsl:with-param name="pis" select="$pis"/>
<xsl:with-param
name="attribute">chunk-first-sections</xsl:with-param>
</xsl:call-template>
</xsl:template>
<xsl:template name="chunk">
<xsl:param name="node" select="."/>
<!-- returns 1 if $node is a chunk -->
<xsl:variable name="dbhtml-chunk-childs">
<xsl:call-template name="dbhtml-chunk-childs">
<xsl:with-param name="pis"
select="$node/parent::*/processing-instruction('dbhtml')"/>
</xsl:call-template>
</xsl:variable>
<xsl:variable name="dbhtml-chunk-first-sections">
<xsl:call-template name="dbhtml-chunk-first-sections">
<xsl:with-param name="pis"
select="$node/ancestor::*[contains(./processing-instruction('dbhtml'),'chunk-first-sections=')][1]/processing-instruction('dbhtml')"/>
</xsl:call-template>
</xsl:variable>
<xsl:if test="$node/@id = 'a1s1'">
<xsl:message>
<xsl:value-of select="$node/@id"/>: <xsl:value-of
select="$dbhtml-chunk-first-sections"/>
</xsl:message>
</xsl:if>
<xsl:choose>
<xsl:when test="not($node/parent::*)">1</xsl:when>
<xsl:when test="local-name($node) = 'sect1'
and ( $dbhtml-chunk-childs = 1 or
($chunk.section.depth >= 1 and $dbhtml-chunk-childs = '') )
and ( ($dbhtml-chunk-first-sections = 1 or
($chunk.first.sections != 0 and $dbhtml-chunk-first-sections = '') )
or count($node/preceding-sibling::sect1)
> 0)">
<xsl:text>1</xsl:text>
</xsl:when>
<xsl:when test="local-name($node) = 'sect2'
and ( $dbhtml-chunk-childs = 1 or
($chunk.section.depth >= 2 and $dbhtml-chunk-childs = '') )
and ( ($dbhtml-chunk-first-sections = 1 or
($chunk.first.sections != 0 and $dbhtml-chunk-first-sections = '') )
or count($node/preceding-sibling::sect2)
> 0)">
<xsl:call-template name="chunk">
<xsl:with-param name="node" select="$node/parent::*"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="local-name($node) = 'sect3'
and ( $dbhtml-chunk-childs = 1 or
($chunk.section.depth >= 3 and $dbhtml-chunk-childs = '') )
and ( ($dbhtml-chunk-first-sections = 1 or
($chunk.first.sections != 0 and $dbhtml-chunk-first-sections = '') )
or count($node/preceding-sibling::sect3)
> 0)">
<xsl:call-template name="chunk">
<xsl:with-param name="node" select="$node/parent::*"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="local-name($node) = 'sect4'
and ( $dbhtml-chunk-childs = 1 or
($chunk.section.depth >= 4 and $dbhtml-chunk-childs = '') )
and ( ($dbhtml-chunk-first-sections = 1 or
($chunk.first.sections != 0 and $dbhtml-chunk-first-sections = '') )
or count($node/preceding-sibling::sect4)
> 0)">
<xsl:call-template name="chunk">
<xsl:with-param name="node" select="$node/parent::*"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="local-name($node) = 'sect5'
and ( $dbhtml-chunk-childs = 1 or
($chunk.section.depth >= 5 and $dbhtml-chunk-childs = '') )
and ( ($dbhtml-chunk-first-sections = 1 or
($chunk.first.sections != 0 and $dbhtml-chunk-first-sections = '') )
or count($node/preceding-sibling::sect5)
> 0)">
<xsl:call-template name="chunk">
<xsl:with-param name="node" select="$node/parent::*"/>
</xsl:call-template>
</xsl:when>
<xsl:when test="local-name($node) = 'section'
and ( $dbhtml-chunk-childs = 1 or
($chunk.section.depth >= count($node/ancestor::section)+1 and
$dbhtml-chunk-childs = '') )
and ( ($dbhtml-chunk-first-sections = 1 or
($chunk.first.sections != 0 and $dbhtml-chunk-first-sections = '') )
or count($node/preceding-sibling::section)
> 0)">
<xsl:call-template name="chunk">
<xsl:with-param name="node" select="$node/parent::*"/>
</xsl:call-template>
</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>
<xsl:when test="name($node)='article'">1</xsl:when>
<xsl:when test="name($node)='part'">1</xsl:when>
<xsl:when test="name($node)='reference'">1</xsl:when>
<xsl:when test="name($node)='refentry'">1</xsl:when>
<xsl:when test="name($node)='index'
and (name($node/parent::*) = 'article'
or name($node/parent::*) =
'book')">1</xsl:when>
<xsl:when test="name($node)='bibliography'
and (name($node/parent::*) = 'article'
or name($node/parent::*) =
'book')">1</xsl:when>
<xsl:when test="name($node)='glossary'
and (name($node/parent::*) = 'article'
or name($node/parent::*) =
'book')">1</xsl:when>
<xsl:when test="name($node)='colophon'">1</xsl:when>
<xsl:when test="name($node)='book'">1</xsl:when>
<xsl:when test="name($node)='set'">1</xsl:when>
<xsl:when test="name($node)='setindex'">1</xsl:when>
<xsl:otherwise>0</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>