xsl:if that depends on if the section is inside a part/chapter or just a part
Here should go questions about transforming XML with XSLT and FOP.
-
- Posts: 23
- Joined: Wed Nov 18, 2015 6:43 pm
xsl:if that depends on if the section is inside a part/chapter or just a part
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>
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: xsl:if that depends on if the section is inside a part/chapter or just a part
Hi,
Your bookmap needs a DITA DOCTYPE so that the @class default attributes get filled. Otherwise, any code (xsl:if or xsl:when) in the stylesheet that depends on the @class attributes has no chance to work. You may have just omitted it from the example you provided. But if you don't have it in your input, that's why nothing works.
Other than that I can only say that there are too many missing pieces of the puzzle to see what's happening in the actual code. This looks like part of a DITA stylesheet customization, that's as much as I can tell.
Regards,
Adrian
Your bookmap needs a DITA DOCTYPE so that the @class default attributes get filled. Otherwise, any code (xsl:if or xsl:when) in the stylesheet that depends on the @class attributes has no chance to work.
Code: Select all
<!DOCTYPE bookmap PUBLIC "-//OASIS//DTD DITA BookMap//EN" "bookmap.dtd">
<bookmap>
...
Other than that I can only say that there are too many missing pieces of the puzzle to see what's happening in the actual code. This looks like part of a DITA stylesheet customization, that's as much as I can tell.
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service