Thanks Tim,
That helps. In addition to chunk.section.depth, there are some other mechanisms for controlling chunking. One is a PI that lets you stop chunking at an arbitrary point and another is the param chunk.first.sections which lets you control whether the first child section is treated as a separate chunk. I also figure that <keyword>s should be included in the html keywords. Perhaps subjectset/subject should be included too? Anyway, I've added support for that stuff and pasted my version below.
The only other mechanism for controlling chunking that's not yet accounted for is the manual method described here
http://www.sagehill.net/docbookxsl/Chunking.html (under "Manually control chunking"). I don't know much about that mechanism and don't know if it could be accounted for easily.
Oh, this also doesn't yet support sect1-style sections, just recursive sections.
David
<xsl:template name="keywordset">
<xsl:variable name="section_level">
<xsl:number value="count(ancestor-or-self::section)"/>
</xsl:variable>
<xsl:variable name="indexterms-and-keywords">
<xsl:choose>
<xsl:when test="$section_level = $chunk.section.depth or ancestor-or-self::*/processing-instruction('dbhtml')[normalize-space(.) ='stop-chunking']">
<xsl:copy-of select=".//indexterm/primary"/>
<xsl:copy-of select=".//keywordset/keyword"/>
</xsl:when>
<xsl:when test="$chunk.first.sections = '0'">
<xsl:copy-of select="./*[not(self::section)]//indexterm/primary|./section[1]//indexterm/primary|./indexterm/primary"/>
<xsl:copy-of select="./*[not(self::section)]//keywordset/keyword|./section[1]//keywordset/keyword|./keywordset/keyword"/>
</xsl:when>
<xsl:otherwise>
<xsl:copy-of select="./*[not(self::section)]//indexterm/primary|./indexterm/primary"/>
<xsl:copy-of select="./*[not(self::section)]//keywordset/keyword|./keywordset/keyword"/>
</xsl:otherwise>
</xsl:choose>
</xsl:variable>
<xsl:variable name="indexterms-and-keywords-unique">
<xsl:for-each select="exslt:node-set($indexterms-and-keywords)/*[not(. = preceding-sibling::*)]">
<xsl:value-of select="normalize-space(.)"/><xsl:if test="not(position() = last())">, </xsl:if>
</xsl:for-each>
</xsl:variable>
<xsl:if test="not($indexterms-and-keywords-unique = '')">
<xsl:attribute name="content">
<xsl:value-of select="$indexterms-and-keywords-unique" />
</xsl:attribute>
</xsl:if>
</xsl:template>
> -----Original Message-----
> From: Tim Arnold [mailto:
Tim.Arnold@sas.com]
> Sent: Friday, September 25, 2009 1:29 PM
> To: DocBook Apps
> Subject: RE: [docbook-apps] automated keywords and chunking
>
> Hi Bob,
> Yes that footnote processing code is pretty complex. I took a
> stab at this first, basing my ideas on the code David sent
> earlier. It works for my toy examples, but maybe it's naïve
> or only works for my situation. To repeat the original problem:
> I'd like to automatically create keywords for each output
> file that consist of the primary index terms in that file.
>
> <xsl:template name="user.head.content">
> <xsl:call-template name="keywordset"/>
> </xsl:template>
>
>
>
> <xsl:template name="keywordset">
>
> <xsl:variable name="section_level">
> <xsl:number value="count(ancestor-or-self::d:section)"/>
> </xsl:variable>
>
>
> <xsl:variable name="indexterms">
> <xsl:choose>
> <xsl:when test="$section_level = $chunk.section.depth">
> <xsl:copy-of select=".//d:indexterm/d:primary"/>
> </xsl:when>
> <xsl:otherwise>
> <xsl:copy-of
> select="./*[not(self::d:section)]//d:indexterm/d:primary|./d:i
ndexterm/d:primary"/>
> </xsl:otherwise>
> </xsl:choose>
> </xsl:variable>
>
>
> <xsl:variable name="indexterms-unique">
> <xsl:for-each select="exslt:node-set($indexterms)/*[not(.
> = preceding-sibling::*)]">
> <xsl:value-of select="normalize-space(.)"/><xsl:if
> test="not(position() = last())">, </xsl:if>
> </xsl:for-each>
> </xsl:variable>
>
>
> <xsl:if test="not($indexterms-unique = '')">
>
> <xsl:attribute name="content">
> <xsl:value-of select="$indexterms-unique" />
> </xsl:attribute>
>
> </xsl:if>
>
> </xsl:template>
>
> > -----Original Message-----
> > From: Bob Stayton [mailto:
bobs@sagehill.net]
> > Sent: Thursday, September 24, 2009 1:04 PM
> > To: Tim Arnold; DocBook Apps
> > Subject: Re: [docbook-apps] automated keywords and chunking
> >
> > Actually, David is correct, and it is more complicated than I
> > originally stated.. The context node when user.head.content
> is called
> > is a chunked section element, but it also includes *all* of its
> > children, including the sections that will be in their own
> chunks and
> > should not be processed for the keywords for the current chunk.
> >
> > The chunking process works by recursive chunking. That is,
> when the
> > current section is chunked, it is processed until a child
> section is
> > reached, at which point the processor will recursively start a new
> > chunk on that, and so on. Only when the last nested section is
> > chunked is the original chunk finished off.
> >
> > This makes it very difficult to detect which indexterms are
> contained
> > in the current chunk by just using XPath from the top of a
> chunk element.
> >
> > Footnote processing in chunked output has a similar problem, as the
> > footnote list at the end of a chunk should only include
> those footnote
> > elements within the current chunk text, not the child
> sections. See
> > the template named 'process.chunk.footnotes' in
> html/chunk-common.xsl
> > and follow where it goes to see how that works to exclude
> footnotes from other chunks.
> >
> > Bob Stayton
> > Sagehill Enterprises
> >
bobs@sagehill.net> >
> >
> > ----- Original Message -----
> > From: "Tim Arnold"