xsl:if that depends on if the section is inside a part/chapter or just a part
Posted: Thu Mar 31, 2016 11:50 pm
Hi there. I have this bookmap:
I would like to place inside templates, xsl:if commands that depend on whether elements are part/chapter or part.
I.e. I had these inside the template processTopicTitle, part of the DITA-OT distribution:
This is not working.
The idea is that the there is a graphic that shows up only in part/chapters, and another on the ones that are only part.
I was given this suggestion but still did not work:
Finally, this is the section where I was putting the code in. I wanted to have a graphic inserted in the title depending if it was a part, part/chapter, as mention above:
Code: Select all
<?xml version="1.0" encoding="utf-8"?>
<bookmap>
<part format ="dita" href="part1title.xml">
<chapter format="ditamap" href="chapter1-1.ditamap"/>
<chapter format="ditamap" href="chapter1-2.ditamap"/>
<chapter format="ditamap" href="chapter1-3.ditamap"/>
</part>
<part format="ditamap" href="part2.ditamap"/>
<part format="ditamap" href="part3.ditamap"/>
<part format="ditamap" href="part4.ditamap"/>
<part format="ditamap" href="part5.ditamap"/>
<appendix format="ditamap" href="appendix1.ditamap"/>
</bookmap>
I.e. I had these inside the template processTopicTitle, part of the DITA-OT distribution:
Code: Select all
<xsl:if test="bookmap/part/chapter">
<fo:external-graphic src="thisischapter.png" />
</xsl:if>
<xsl:if test="bookmap/part">
<fo:external-graphic src="thisispart.png" />
</xsl:if>
The idea is that the there is a graphic that shows up only in part/chapters, and another on the ones that are only part.
I was given this suggestion but still did not work:
Code: Select all
<xsl:choose>
<!-- parts -->
<xsl:when test="$map//*[contains(@class, ' bookmap/part ')]">
<fo:external-graphic src="thisispart.png" />
</xsl:when>
<!-- chapters -->
<xsl:when test="$map//*[contains(@class, ' bookmap/chapter ')]">
<fo:external-graphic src="thisischapter.png" />
</xsl:when>
<!-- parts without chapters -->
<xsl:when test="$map//*[contains(@class, ' bookmap/part ')][not(child::*[contains(@class, ' bookmap/chapter ')])">
<fo:external-graphic src="thisispart.png" />
</xsl:when>
</xsl:choose>
Code: Select all
<xsl:template match="*" mode="processTopicTitle">
<xsl:variable name="level" as="xs:integer">
<xsl:apply-templates select="." mode="get-topic-level"/>
</xsl:variable>
<xsl:variable name="attrSet1">
<xsl:apply-templates select="." mode="createTopicAttrsName">
<xsl:with-param name="theCounter" select="$level"/>
</xsl:apply-templates>
</xsl:variable>
<xsl:variable name="attrSet2" select="concat($attrSet1, '__content')"/>
<fo:block>
<xsl:call-template name="commonattributes"/>
<xsl:call-template name="processAttrSetReflection">
<xsl:with-param name="attrSet" select="$attrSet1"/>
<xsl:with-param name="path" select="'../../cfg/fo/attrs/commons-attr.xsl'"/>
</xsl:call-template>
<fo:block>
<xsl:call-template name="processAttrSetReflection">
<xsl:with-param name="attrSet" select="$attrSet2"/>
<xsl:with-param name="path" select="'../../cfg/fo/attrs/commons-attr.xsl'"/>
</xsl:call-template>
<xsl:if test="$level = 1">
<fo:marker marker-class-name="current-header">
<xsl:apply-templates select="." mode="getTitle"/>
</fo:marker>
</xsl:if>
<xsl:if test="$level = 2">
<fo:marker marker-class-name="current-h2">
<xsl:apply-templates select="." mode="getTitle"/>
</fo:marker>
</xsl:if>
<fo:inline id="{parent::node()/@id}"/>
<xsl:choose>
<!-- parts -->
<xsl:when test="$map//*[contains(@class, ' bookmap/part ')]">
<fo:external-graphic src="thisispart.png" />
</xsl:when>
<!-- chapters -->
<xsl:when test="$map//*[contains(@class, ' bookmap/chapter ')]">
<fo:external-graphic src="thisischapter.png" />
</xsl:when>
<!-- parts without chapters -->
<xsl:when test="$map//*[contains(@class, ' bookmap/part ')][not(child::*[contains(@class, ' bookmap/chapter ')])">
<fo:external-graphic src="thisispart.png" />
</xsl:when>
</xsl:choose>
<fo:inline>
<xsl:attribute name="id">
<xsl:call-template name="generate-toc-id">
<xsl:with-param name="element" select=".."/>
</xsl:call-template>
</xsl:attribute>
</fo:inline>
<xsl:call-template name="pullPrologIndexTerms"/>
<xsl:apply-templates select="." mode="getTitle"/>
</fo:block>
</fo:block>
</xsl:template>