[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]
Subject: Re: [docbook-apps] Nested Sections From Block to Inline
Hi Keith,
I think you can solve your problem with more detailed XPath selections and
using modes. As you point out, you don't want to attempt this on sections
that don't start with a para, but you also can't rely on position like [2]
since a section could have a sectioninfo (or info in DB5) as well as a
title.
This template selects a section that meets these requirements:
<xsl:template match="section[count(ancestor::section) > 2]
[child::*[not(self::title) and
not(self::sectioninfo) and
not(self::info)][1][self::para]]">
<xsl:message>got here</xsl:message>
<xsl:apply-templates select="child::*[not(self::title) and
not(self::sectioninfo) and
not(self::info)][1][self::para]"
mode="run.in.para"/>
<xsl:apply-templates select="child::*[not(self::title) and
not(self::sectioninfo) and
not(self::para[1])]"/>
</xsl:template>
The first predicate selects level 4 and higher sections by counting section
ancestors. The second predicate selects all children of one of those
sections, and then selects out title, sectioninfo, and info. It then takes
the first remaining child [1], and tests to see if it is a para with
self::para. So this template should handle only those sections whose first
content is a para, and all other sections at that level would be handled by
the regular section template.
Then it applies templates in mode="run.in.para" to that first para, and
then applies templates in normal mode for all other children after the
title, info, and first para.
The template to handle the first para looks something like this:
<xsl:template match="para" mode="run.in.para">
<fo:block xsl:use-attribute-sets="normal.para.spacing">
<xsl:call-template name="anchor"/>
<xsl:apply-templates select="ancestor::section[1]/title"
mode="grabme"/>
<xsl:apply-templates/>
</fo:block>
</xsl:template>
It selects its closest ancestor's section title to process in the mode you
described to generate the fo:inline, then processes the rest of the para's
content in the same block. You'll probably have to improve this a bit, but
it should get you started.
Bob Stayton
Sagehill Enterprises
DocBook Consulting
bobs@sagehill.net
----- Original Message -----
From: "Keith Fahlgren" <abdelazer@gmail.com>
To: "Bob Stayton" <bobs@sagehill.net>
Cc: "apps docbook" <docbook-apps@lists.oasis-open.org>
Sent: Wednesday, October 11, 2006 7:27 AM
Subject: Re: [docbook-apps] Nested Sections From Block to Inline
> On 10/10/06, Bob Stayton <bobs@sagehill.net> wrote:
>> Hi Keith,
>> Take a look in titlepage.templates.xsl. That's the stylesheet module
>> generated from the titlepage spec file, and it also adds fo:blocks.
>
> Ah, of course! I somehow managed to convince myself that that was
> _not_ the place yesterday...
>
> I've now got exactly what I was looking for with the sect4/title, that
> is, it's wrapped in an fo:inline. My next issue is how to get that
> fo:inline inside the following fo:block.
>
> Let's pretend the markup is:
>
> <section id="4th-level">
> <title>HeadD</title>
> <para>The quick brown...</para>
> ...
>
> Here's what I'm currently generating:
> <fo:block id="section-wrapper">
> <fo:inline font="bar">
> <fo:inline>Head</fo:inline>
> </fo:inline>
> <fo:block font="foo">The quick brown...
> ...
>
> Suggestions on how to move the fo:inline inside the fo:block?
>
> My current best guess is to match sect4/*[2], but I don't know how to
> ensure normal processing of that thing (<para>, in this case) once
> I've done an
> <xsl:apply-templates select="title" mode="grabme"/>
> (since I have no idea whether it'll be a <para> or a <orderedlist> or
> whatever).
>
> Also, the problem compounds when I need to match section/*[2] but
> check if it's $level = 4.
>
> Ideas?
>
> ---------------------------------
> For the record, here's how I got rid of all of the fo:blocks on my way
> to having run-in 4th-level heads (the nested <section>s being the
> annoying part). Similar, but simpler changes need to be made to the
> sect4 templates...
>
> [note: just snippets, not well-formed]:
>
> sections.xsl:
>
> <xsl:template match="section/title
> |simplesect/title
> |sect1/title
> |sect2/title
> |sect3/title
> |sect4/title
> |sect5/title"
> mode="titlepage.mode"
> priority="2">
> <!-- pull _all_ of the variable defs up here -->
> <xsl:choose>
> <xsl:when test="$level = 4">
> <xsl:call-template name="section.heading">
> <xsl:with-param name="level" select="$level"/>
> <xsl:with-param name="title" select="$title"/>
> <xsl:with-param name="marker" select="$marker"/>
> <xsl:with-param name="titleabbrev" select="$titleabbrev.elem"/>
> </xsl:call-template>
> </xsl:when>
> <xsl:otherwise>
> <!-- all the regular stuff -->
>
> <xsl:template name="section.heading">
> <xsl:param name="level" select="1"/>
> <xsl:param name="marker" select="1"/>
> <xsl:param name="title"/>
> <xsl:param name="titleabbrev"/>
>
> <xsl:choose>
> <xsl:when test="$level = 4">
> <!-- interesting part here -->
> <fo:inline
> xsl:use-attribute-sets="section.title.level4.properties
> orm.section.level4.properties">
> <fo:marker marker-class-name="section.head.marker">
> <xsl:choose>
> <xsl:when test="$titleabbrev = ''">
> <xsl:value-of select="$title"/>
> </xsl:when>
> <xsl:otherwise>
> <xsl:value-of select="$titleabbrev"/>
> </xsl:otherwise>
> </xsl:choose>
> </fo:marker>
> <xsl:copy-of select="$title"/>
> <!-- my trailing punctuation... -->
> <xsl:text>.</xsl:text>
> </fo:inline>
> </xsl:when>
> <xsl:otherwise>
> <!-- regular stuff here -->
>
> titlepage.templates.xsl:
> <xsl:template name="sect4.titlepage.recto">
> <xsl:choose>
> <xsl:when test="sect4info/title">
> <xsl:apply-templates mode="sect4.titlepage.recto.auto.mode"
> select="sect4info/title"/>
> </xsl:when>
> <xsl:when test="info/title">
> <xsl:apply-templates mode="sect4.titlepage.recto.auto.mode"
> select="info/title"/>
> </xsl:when>
> <!-- not yet!
> <xsl:when test="title">
> <xsl:apply-templates mode="sect4.titlepage.recto.auto.mode"
> select="title"/>
> </xsl:when>
> -->
> <!-- rest is normal -->
>
> <xsl:template name="section.titlepage">
> <xsl:variable name="renderas">
> <xsl:choose>
> <xsl:when test="@renderas = 'sect1'">1</xsl:when>
> <xsl:when test="@renderas = 'sect2'">2</xsl:when>
> <xsl:when test="@renderas = 'sect3'">3</xsl:when>
> <xsl:when test="@renderas = 'sect4'">4</xsl:when>
> <xsl:when test="@renderas = 'sect5'">5</xsl:when>
> <xsl:otherwise><xsl:value-of select="''"/></xsl:otherwise>
> </xsl:choose>
> </xsl:variable>
> <xsl:variable name="level">
> <xsl:choose>
> <xsl:when test="$renderas != ''">
> <xsl:value-of select="$renderas"/>
> </xsl:when>
> <xsl:otherwise>
> <xsl:call-template name="section.level"/>
> </xsl:otherwise>
> </xsl:choose>
> </xsl:variable>
> <xsl:choose>
> <xsl:when test="$level = 4">
> <xsl:variable name="recto.content">
> <xsl:call-template name="section.titlepage.before.recto"/>
> <xsl:call-template name="section.titlepage.recto"/>
> </xsl:variable>
> <xsl:variable name="recto.elements.count">
> <xsl:choose>
> <xsl:when
> test="function-available('exsl:node-set')"><xsl:value-of
> select="count(exsl:node-set($recto.content)/*)"/></xsl:when>
> <xsl:otherwise>1</xsl:otherwise>
> </xsl:choose>
> </xsl:variable>
> <xsl:if test="(normalize-space($recto.content) != '') or
> ($recto.elements.count > 0)">
> <xsl:copy-of select="$recto.content"/>
> </xsl:if>
> <xsl:variable name="verso.content">
> <xsl:call-template name="section.titlepage.before.verso"/>
> <xsl:call-template name="section.titlepage.verso"/>
> </xsl:variable>
> <xsl:variable name="verso.elements.count">
> <xsl:choose>
> <xsl:when
> test="function-available('exsl:node-set')"><xsl:value-of
> select="count(exsl:node-set($verso.content)/*)"/></xsl:when>
> <xsl:otherwise>1</xsl:otherwise>
> </xsl:choose>
> </xsl:variable>
> <xsl:if test="(normalize-space($verso.content) != '') or
> ($verso.elements.count > 0)">
> <xsl:copy-of select="$verso.content"/>
> </xsl:if>
> <xsl:call-template name="section.titlepage.separator"/>
> </xsl:when>
> <xsl:otherwise>
> <!-- normal stuff -->
>
> <xsl:template match="title" mode="section.titlepage.recto.auto.mode">
> <xsl:variable name="renderas">
> <xsl:choose>
> <xsl:when test="../@renderas = 'sect1'">1</xsl:when>
> <xsl:when test="../@renderas = 'sect2'">2</xsl:when>
> <xsl:when test="../@renderas = 'sect3'">3</xsl:when>
> <xsl:when test="../@renderas = 'sect4'">4</xsl:when>
> <xsl:when test="../@renderas = 'sect5'">5</xsl:when>
> <xsl:otherwise><xsl:value-of select="''"/></xsl:otherwise>
> </xsl:choose>
> </xsl:variable>
> <xsl:variable name="level">
> <xsl:choose>
> <xsl:when test="$renderas != ''">
> <xsl:value-of select="$renderas"/>
> </xsl:when>
> <xsl:otherwise>
> <xsl:call-template name="section.level">
> <xsl:with-param name="node" select=".."/>
> </xsl:call-template>
> </xsl:otherwise>
> </xsl:choose>
> </xsl:variable>
> <xsl:choose>
> <xsl:when test="$level = 4">
> <!-- dunno if I should do nested inlines or not... -->
> <fo:inline xmlns:fo="http://www.w3.org/1999/XSL/Format"
> xsl:use-attribute-sets="section.titlepage.recto.style"
> margin-left="{$title.mar
> <xsl:apply-templates select="."
> mode="section.titlepage.recto.mode"/>
> </fo:inline>
> </xsl:when>
> <xsl:otherwise>
> <fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format"
> xsl:use-attribute-sets="section.titlepage.recto.style"
> margin-left="{$title.marg
> <xsl:apply-templates select="."
> mode="section.titlepage.recto.mode"/>
> </fo:block>
> </xsl:otherwise>
> </xsl:choose>
> </xsl:template>
>
>
> HTH,
> Keith
>
>
[Date Prev] | [Thread Prev] | [Thread Next] | [Date Next] -- [Date Index] | [Thread Index] | [List Home]