Page 1 of 1

Apply a specific attribute only on chunked topics

Posted: Sat Dec 17, 2022 5:24 pm
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?

Re: Apply a specific attribute only on chunked topics

Posted: Mon Dec 19, 2022 8:04 am
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

Re: Apply a specific attribute only on chunked topics

Posted: Mon Dec 26, 2022 9:14 pm
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"/>