Apply a specific attribute only on chunked topics

Post here questions and problems related to editing and publishing DITA content.
gbv34
Posts: 105
Joined: Thu Jan 20, 2022 12:36 pm

Apply a specific attribute only on chunked topics

Post by gbv34 »

Hello,
I'm currently having difficulties with a transformation in a plugin whose purpose is to apply a custom attribute to chunked topics.

Concretely, I have topicrefs with chunked topics in a map that contains an outputclass that will serve for the transformation:

Code: Select all

 <topicref href="colors/t_introduction.dita"  chunk="to-content">
                           <topicref href="colors/t_orange.dita" outputclass="tabbed-title=Orange"/>
                           <topicref href="colors/t_green.dita" outputclass="tabbed-title=Green"/>
                           <topicref href="colors/t_gray.dita" outputclass="tabbed-title=Gray"/>
                           <topicref href="colors/t_black.dita" outputclass="tabbed-title=Black"/>      
                  </topicref>
My transformation should chunk these topics together. Thanks to an XSL, I will use the tabbed-title outputclass to be transformed into another attribute name.

Code: Select all

   <xsl:template match="*[contains(@class, ' topic/topic ')]" mode="child.topic" name="child.topic">
        <xsl:param name="nestlevel" as="xs:integer">
            <xsl:choose>
                <!-- Limit depth for historical reasons, could allow any depth. Previously limit was 5. -->
                <xsl:when test="count(ancestor::*[contains(@class, ' topic/topic ')]) > 9"
                    >9</xsl:when>
                <xsl:otherwise>
                    <xsl:sequence select="count(ancestor::*[contains(@class, ' topic/topic ')])"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:param>
        <xsl:variable name="topic_id" select="@id"/>
        <xsl:variable name="attributeValue">
            <xsl:value-of select="$mapDoc//topicref[contains(@href, $topic_id)]/@outputclass"/>
        </xsl:variable>

        <article class="globalTopic">
            <xsl:variable name="apos">'</xsl:variable>     
            <xsl:if test="contains($attributeValue, 'tabbed-title=')">
                <xsl:attribute name="data-ft-tab-label">
                    <xsl:value-of select="substring-after(translate($attributeValue, $apos, ''),'=')"/>
                 </xsl:attribute>
            </xsl:if>
            <xsl:call-template name="gen-topic">
                <xsl:with-param name="nestlevel" select="$nestlevel"/>
            </xsl:call-template>   
        </article>
    </xsl:template>
Everything works fine except that the top div with the class "globalTopic" will also receive the attribute data-ft-tab-label whereas I try to apply only to the nested topics.

Currently, the HTML source displays for the parent topic this:

Code: Select all

<div class="globalTopic" aria-labelledby="ariaid-title1" data-ft-tab-label="Orange tabbed-title=Green tabbed-title=Gray tabbed-title=Black">
....
<div class="topic nested1" aria-labelledby="ariaid-title2" data-ft-tab-label="Orange" id="t_orange">...</div>
<div class="topic nested1" aria-labelledby="ariaid-title3" data-ft-tab-label="Green" id="t_green">...</div>
</div>
By any chance, do you have any suggestion?
------
Gaspard
Radu
Posts: 9437
Joined: Fri Jul 09, 2004 5:18 pm

Re: Apply a specific attribute only on chunked topics

Post by Radu »

Hi Gaspard,
I think you should try to debug this more on your side.
So the "$mapDoc" variable contains the DITA Map loaded some place else using the document() function, right?
How about if you use an xsl:message to output to the console the " <xsl:variable name="topic_id" select="@id"/>" topic ID? Are all IDs of the referenced topics unique? Because they are not enforced to be unique, two topics can have the same ID as long as they are in different files.
You should probably use an xsl:message to output this value " <xsl:value-of select="$mapDoc//topicref[contains(@href, $topic_id)]/@outputclass"/>" and see that the returned output class value is. For example I do not understand why you are searching for the topic ID in the topicref @href value. The sample DITA Map you posted does not contain the topic ID in the topicref href values.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
gbv34
Posts: 105
Joined: Thu Jan 20, 2022 12:36 pm

Re: Apply a specific attribute only on chunked topics

Post by gbv34 »

Problem solved, Radu! Thanks for your pointers.
The issue was related to this variable definition:

Code: Select all

  <xsl:variable name="attributeValue">
            <xsl:value-of select="$mapDoc//topicref[contains(@href, $topic_id)]/@outputclass"/>
        </xsl:variable>
I updated it with:

Code: Select all

 <xsl:value-of select="$mapDoc//topicref[ends-with(@href, $topic_id)]/@outputclass"/>
------
Gaspard
Post Reply