2

I have this piece of code, modified from the DITA-OT original distribution:

<xsl:template match="*[contains(@class, ' topic/topic ')]" mode="in-this-section-chapter-list">
    <fo:block margin-left="6em">
        <fo:block>
            <xsl:call-template name="insertVariable">
                <xsl:with-param name="theVariableID" select="'Chapter with number'"/>
                <xsl:with-param name="theParameters">
                    <number>
                        <fo:inline>
                            <xsl:apply-templates select="key('map-id', @id)[1]"
                                mode="topicTitleNumber"/>
                        </fo:inline>
                    </number>
                </xsl:with-param>
            </xsl:call-template>
        </fo:block>
    </fo:block>
</xsl:template>

I am trying to only execute/print this mini-toc, when this is a Part that has Chapters as child nodes (see below), but not when it is only a Part without any Chapters, in a book like this:

<?xml version="1.0" encoding="utf-8"?>
<bookmap>
<part>
    <chapter/>
    <chapter/>
    <chapter/>
</part>
<part/>
<part/>
<part/>
<part/>
<appendix/>
</bookmap>

So in this case, only the first <part> would execute/print this.

I thought that passing the value from <xsl:apply-templates select="key('map-id', @id)[1]" mode="topicTitleNumber"/> as text, would allow me to add an if that basically will test for a value that is not empty, thus executing this. But it has not worked.

I came up with something like this, which is not valid:

<xsl:template match="*[contains(@class, ' topic/topic ')]" mode="in-this-section-chapter-list">

<xsl:with-param name="value-number">
    <xsl:apply-templates select="key('map-id', @id)[1]"
        mode="topicTitleNumber"/>
</xsl:with-param>

<xsl:if test="$value-number!=''">
    <fo:block margin-left="6em">
        <fo:block>
            <xsl:call-template name="insertVariable">
                <xsl:with-param name="theVariableID" select="'Chapter with number'"/>
                <xsl:with-param name="theParameters">
                    <number>
                        <fo:inline>
                            <xsl:apply-templates select="key('map-id', @id)[1]"
                                mode="topicTitleNumber"/>
                        </fo:inline>
                    </number>
                </xsl:with-param>
            </xsl:call-template>
        </fo:block>
    </fo:block>
</xsl:if>
</xsl:template>
User0123456789
  • 760
  • 2
  • 10
  • 25
Jose Cotes
  • 31
  • 3
  • 1
    To say something her at least the key declaration for map-id and the used template with `mode="topicTitleNumber"` is required. A guess would be that this template generate some xml. Than you can't use that as text without an xslt extension. – hr_117 Mar 15 '16 at 20:48

2 Answers2

2

For the template to match only part that contain chapter, change match="*[contains(@class, ' topic/topic ')]" to match="part[chapter][contains(@class, ' topic/topic ')]".

You might no longer need the [contains(@class, ' topic/topic ')] if the predicate is going to be true for every part that you're interested in. And you really don't want it if it's going to be false for any of the part that you're interested in.

Tony Graham
  • 7,306
  • 13
  • 20
0

You may also need to add an OR so that you pick up chapter if you want the minitoc at the chapter level.

JulioV
  • 516
  • 2
  • 3