Generate text for collection-type="choice"

steinbacherGE
Posts: 48
Joined: Tue Mar 13, 2018 6:07 pm

Generate text for collection-type="choice"

Post by steinbacherGE » Fri Jul 17, 2020 12:06 am

How can I extend Webhelp Responsive to generate text above the child links for collection-type="choice"? This text would say something like, "Please chose from the following options." The author's intent is to have a user choose from one of the nested topics, but that is not clear in the generated output.

Here is the context of the source ditamap.

Code: Select all

<topicref href="t_parentTask.dita" collection-type="choice">
	<topicref href="t_choice1.dita"/>
	<topicref href="t_choice2.dita"/>
	<topicref href="t_choice3.dita"/>
</topicref>
When I published I noticed that t_parentTask.dita in the temp folder includes the collection-type="choice" in the linkpool element.

Code: Select all

<linkpool class="- topic/linkpool " collection-type="choice" xtrc="topicref:2;55:73" xtrf="file:/C:/dita-ot-3.4-Dev/samples/Test/bm_test.ditamap">
<link class="- topic/link " format="dita" href="t_choice1.dita" mapclass="- map/topicref " role="child" scope="local" type="task" xtrc="topicref:3;56:50" xtrf="file:/C:/dita-ot-3.4-Dev/samples/Test/bm_test.ditamap">
<?ditaot usertext?>
<linktext class="- topic/linktext ">
<?ditaot gentext?>Choice 1</linktext>
</link>
<link class="- topic/link " format="dita" href="t_choice2.dita" mapclass="- map/topicref " role="child" scope="local" type="task" xtrc="topicref:4;57:50" xtrf="file:/C:/dita-ot-3.4-Dev/samples/Test/bm_test.ditamap">
<?ditaot usertext?>
<linktext class="- topic/linktext ">
<?ditaot gentext?>Choice 2</linktext>
</link>
<link class="- topic/link " format="dita" href="t_choice3.dita" mapclass="- map/topicref " role="child" scope="local" type="task" xtrc="topicref:5;58:50" xtrf="file:/C:/dita-ot-3.4-Dev/samples/Test/bm_test.ditamap">
<?ditaot usertext?>
<linktext class="- topic/linktext ">
<?ditaot gentext?>Choice 3</linktext>
</link>
</linkpool>
But the html output doesn't include any collection-type information.

Code: Select all

<div class=" wh_child_links ">
<nav role="navigation" class="- topic/related-links related-links">
<ul class="ullinks">
<li class="- topic/link link ulchildlink"><strong><a href="t_choice1.html">Choice 1</a></strong></li>
<li class="- topic/link link ulchildlink"><strong><a href="t_choice2.html">Choice 2</a></strong></li>
<li class="- topic/link link ulchildlink"><strong><a href="t_choice3.html">Choice 3</a></strong></li>
</ul></nav></div>
Is there a way to pass the collection-type="choice" value to the HTML output? If so, I think I can use CSS to generate text.

However, my preference would be to use a string file and include it within an XSL template. Any suggestions which template to start with?

Thanks,

Leroy Steinbacher

cosmin_andrei
Posts: 71
Joined: Mon Jun 12, 2017 10:50 am

Re: Generate text for collection-type="choice"

Post by cosmin_andrei » Mon Jul 20, 2020 4:56 pm

Hi Leroy,

We logged an improvement request in our internal tracking system, so it will be analyzed by the development team. In case this will be implemented in the future, we will notify this thread.
Regards,
Cosmin
--
Cosmin Andrei
oXygen XML Editor and Author Support

steinbacherGE
Posts: 48
Joined: Tue Mar 13, 2018 6:07 pm

Re: Generate text for collection-type="choice"

Post by steinbacherGE » Wed May 05, 2021 7:56 pm

I figured out a way to add generated text above child links for collection type="choice"

I added a template that pulls in the collection-type="choice" from the linkpool element used in the DITA temp files. It also pulls in the generated text from a string file.

Then I had to add the <nav> element from the related-links template in this file.

\com.oxygenxml.webhelp.responsive\xsl\dita2webhelp\html5-pdf-webhelp\html5-rel-links.xsl

Code: Select all

    <xsl:template match="*[contains(@class, ' topic/related-links ')]
        [descendant::*[contains(@class, ' topic/linkpool ')][@collection-type = 'choice']]" name="topic.related-links">
        <xsl:if test="oxy:getParameter('webhelp.show.child.links') = 'yes'">
            <div class="topic-choices-label">
                <xsl:call-template name="getWebhelpString">
                    <xsl:with-param name="stringName" select="'choice'"/>
                </xsl:call-template>
            </div>
        </xsl:if>
        
            <nav role="navigation">
                <xsl:call-template name="commonattributes"/>
                <xsl:if test="$include.roles = ('child', 'descendant')">
                    <xsl:call-template name="ul-child-links"/>
                    <!--handle child/descendants outside of linklists in collection-type=unordered or choice-->
                    <xsl:call-template name="ol-child-links"/>
                    <!--handle child/descendants outside of linklists in collection-type=ordered/sequence-->
                </xsl:if>
                <xsl:variable name="unordered-links" as="element(linklist)*">
                    <xsl:apply-templates select="." mode="related-links:group-unordered-links">
                        <xsl:with-param name="nodes"
                            select="descendant::*[contains(@class, ' topic/link ')]
                            [not(related-links:omit-from-unordered-links(.))]
                            [generate-id(.) = generate-id(key('hideduplicates', related-links:hideduplicates(.))[1])]"/>
                    </xsl:apply-templates>
                </xsl:variable>
                <xsl:apply-templates select="$unordered-links"/>
                <!--linklists - last but not least, create all the linklists and their links, with no sorting or re-ordering-->
                <xsl:apply-templates select="*[contains(@class, ' topic/linklist ')]"/>
            </nav>
    </xsl:template>

Is this the best way to handle this? Any suggestions to improve this method?

Here is our output:
image.png
image.png (15.56 KiB) Viewed 254 times

radu_pisoi
Posts: 386
Joined: Thu Aug 21, 2003 11:36 am
Location: Craiova
Contact:

Re: Generate text for collection-type="choice"

Post by radu_pisoi » Thu May 13, 2021 2:28 pm

Hi,

Thank you for sharing with us your customization.

I think I have two improvement suggestions:
1. If you want to extend WebHelp functionality by changing the XSLT code, it is recommended to create a publishing template and use the XSLT extension points.
Please see the How to Use XSLT Extension Points from a Publishing Template topic for an implementation example.

2. When you want to overwrite an XSLT template from WebHelp or DITA-OT, it might be a good idea to use xsl:apply-imports instruction to get functionality from the original template (the template you overwrite). This technique allows you to get changes from the template you overwrite when you upgrade WebHelp or DITA-OT to a newer version.

A sample implementation could be:

Code: Select all

<xsl:template match="*[contains(@class, ' topic/related-links ')]
        [descendant::*[contains(@class, ' topic/linkpool ')][@collection-type = 'choice']]">
        <xsl:if test="oxy:getParameter('webhelp.show.child.links') = 'yes'">
            <div class="topic-choices-label">
                <xsl:call-template name="getWebhelpString">
                    <xsl:with-param name="stringName" select="'choice'"/>
                </xsl:call-template>
            </div>
        </xsl:if>
        
        <xsl:apply-imports/>        
    </xsl:template>
Radu Pisoi
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Post Reply