Converting an xsl:apply-templates into a string value to use as an if parameter

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>

Answers


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.


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


Need Your Help

How to Disable CSS of one of two col-md-12 divs

css twitter-bootstrap

I have made 2 Divisions out of bootstrap property &lt;div class="col-md-12" &gt; on the same page. In the first one, I have added a different Background and some hover property, now in the second o...

How to display holiday in java?

java

I am trying to make a calendar application in Java and have successfully completed the calendar display part. Now, I need to display Holiday messages below the calendar entries.