Page 1 of 1

Override sidetoc.xsl aria-label

Posted: Tue Jun 01, 2021 4:26 pm
by ckabstein
Hello,

We have set our focus on making our webhelp responsive output as accessible as possible.
I've noticed that in some XSL files, some aria-labels haven't been localized yet.
Tried to add them myself and failed. :wink:

I've only got to the point that at least our customized strings-en-us.xml file is used, but the other strings-xx-xx files are not used.
It looks like the processing loses the language part somewhere, and I don't know why.
Normally, I would have only tunneled the i18n_context parameter - which worked in my other XSLs - but this time, I needed to import the functions.xsl file (the visible import is only a quick fix. I know it should be done otherwise.) and redefine the webhelp.language and i18n_context variables as was done elsewhere in the com.oxygenxml.webhelp.responsive plug-in. Otherwise, only the label defined in <xsl:otherwise> was used.
I've also redefined the variable to insert the label.home string, but to no avail.

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:toc="http://www.oxygenxml.com/ns/webhelp/toc" xmlns="http://www.w3.org/1999/xhtml"
    xmlns:xhtml="http://www.w3.org/1999/xhtml"
    xmlns:st="http://www.oxygenxml.com/ns/webhelp/side-toc" 
    xmlns:oxygen="http://www.oxygenxml.com/functions"
    exclude-result-prefixes="xs toc st xhtml" version="2.0">
    
    <xsl:import href="../../com.oxygenxml.webhelp.responsive/xsl/util/functions.xsl"/>
    
    <xsl:variable name="webhelp_language" select="oxygen:getParameter('webhelp.language')"/>
    
    <xsl:variable name="i18n_context">
        <i18n_context>
            <xsl:attribute name="xml:lang" select="$webhelp_language"/>
            <xsl:attribute name="lang" select="$webhelp_language"/>
            <xsl:attribute name="dir" select="oxygen:getParameter('webhelp.page.direction')"/>
        </i18n_context>
    </xsl:variable>    
    
    <xsl:template match="xhtml:ul" mode="toc-accessibility">
        <xsl:copy>
            <xsl:variable name="isRoot" as="xs:boolean" select="count(parent::*) = 0"/>
            <xsl:attribute name="role">
                <xsl:choose>
                    <xsl:when test="$isRoot">
                        <xsl:value-of>tree</xsl:value-of>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of>group</xsl:value-of>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:attribute>
            <xsl:apply-templates select="@*" mode="toc-accessibility"/>
            <xsl:if test="$isRoot">                
                <xsl:attribute name="aria-label">
                    <xsl:choose>
                        <xsl:when test="exists($i18n_context)">                            
                            <xsl:for-each select="$i18n_context[1]">
                                <xsl:call-template name="getWebhelpString">
                                    <xsl:with-param name="stringName" select="'label.home'"/>
                                </xsl:call-template>
                            </xsl:for-each>
                        </xsl:when>
                        <xsl:otherwise>Table of Contents</xsl:otherwise>
                    </xsl:choose>
                </xsl:attribute>
                <span class="expand-button-action-labels">
                    <span id="{$expandActionID}" aria-label="Expand"/>
                    <span id="{$collapseActionID}" aria-label="Collapse"/>
                    <span id="{$pendingActionID}" aria-label="Pending"/>
                </span>
            </xsl:if>
            
            <xsl:apply-templates select="node()" mode="toc-accessibility"/>
        </xsl:copy>
    </xsl:template>    
</xsl:stylesheet>
What have I done wrong?

Best,
Christina

Re: Override sidetoc.xsl aria-label

Posted: Thu Jun 24, 2021 4:08 pm
by ckabstein
Hello,

I haven't received a reply yet.

I would appreciate any kind of help.

Thanks,
Christina

Re: Override sidetoc.xsl aria-label

Posted: Tue Jun 29, 2021 9:06 pm
by alin
Hello Christina,

The issue you are facing is because the oxygen:getParameter() function does not work properly.
To fix it, first you have to declare the following parameters in your stylesheet:

Code: Select all

<xsl:param name="TEMP_DIR_URL"/>
<xsl:param name="WEBHELP_PARAMETERS_URL" select="concat($TEMP_DIR_URL, 'props.xml')"></xsl:param>
Next, you have to import the functions.xsl stylesheet (as you have already noticed). To correctly import it you need to add the following import declaration:

Code: Select all

<xsl:import href="plugin:com.oxygenxml.webhelp.responsive:xsl/util/functions.xsl"/>

Now the oxygen:getParameter() should work as expected.
In addition to this, in order for the getWebhelpString template to correctly localize the strings it should be called as follows:

Code: Select all

           <xsl:for-each select="$i18n_context[1]/*">
                <xsl:call-template name="getWebhelpString">
                    <xsl:with-param name="stringName" select="'label.home'"/>
                </xsl:call-template>
            </xsl:for-each>
Please nothe the /* in the for-each select clause.

Below you can find the modified stylesheet (I added some log messages to test that it works properly):

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:toc="http://www.oxygenxml.com/ns/webhelp/toc" xmlns="http://www.w3.org/1999/xhtml"
    xmlns:xhtml="http://www.w3.org/1999/xhtml"
    xmlns:st="http://www.oxygenxml.com/ns/webhelp/side-toc" 
    xmlns:oxygen="http://www.oxygenxml.com/functions"
    exclude-result-prefixes="xs toc st xhtml" version="2.0">
    
    <xsl:param name="TEMP_DIR_URL"/>
    <xsl:param name="WEBHELP_PARAMETERS_URL" select="concat($TEMP_DIR_URL, 'props.xml')"></xsl:param>
    
   <!-- <xsl:import href="../../com.oxygenxml.webhelp.responsive/xsl/util/functions.xsl"/>-->
    <xsl:import href="plugin:com.oxygenxml.webhelp.responsive:xsl/util/functions.xsl"/>
    
    <xsl:variable name="webhelp_language" select="oxygen:getParameter('webhelp.language')"/>

    <xsl:variable name="i18n_context">
        <i18n_context>
            <xsl:attribute name="xml:lang" select="$webhelp_language"/>
            <xsl:attribute name="lang" select="$webhelp_language"/>
            <xsl:attribute name="dir" select="oxygen:getParameter('webhelp.page.direction')"/>
        </i18n_context>
    </xsl:variable>    
    
    <xsl:template match="xhtml:ul" mode="toc-accessibility">
        <xsl:message> --------------- TEMP_DIR_URL: <xsl:value-of select="$TEMP_DIR_URL"/></xsl:message>
        <xsl:message> --------------- WEBHELP_PARAMETERS_URL: <xsl:value-of select="$WEBHELP_PARAMETERS_URL"/></xsl:message>
        <xsl:message> --------------- WH LANG: <xsl:value-of select="oxygen:getParameter('webhelp.language')"/></xsl:message>
        <xsl:message> Search i18n: 
            <xsl:for-each select="$i18n_context[1]/*">
                <xsl:call-template name="getWebhelpString">
                    <xsl:with-param name="stringName" select="'webhelp.search'"/>
                </xsl:call-template>
            </xsl:for-each>
        </xsl:message>
        
        <xsl:copy>
            <xsl:variable name="isRoot" as="xs:boolean" select="count(parent::*) = 0"/>
            <xsl:attribute name="role">
                <xsl:choose>
                    <xsl:when test="$isRoot">
                        <xsl:value-of>tree</xsl:value-of>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of>group</xsl:value-of>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:attribute>
            <xsl:apply-templates select="@*" mode="toc-accessibility"/>
            <xsl:if test="$isRoot">                
                <xsl:attribute name="aria-label">
                    <xsl:choose>
                        <xsl:when test="exists($i18n_context)">                            
                            <xsl:for-each select="$i18n_context[1]">
                                <xsl:call-template name="getWebhelpString">
                                    <xsl:with-param name="stringName" select="'label.home'"/>
                                </xsl:call-template>
                            </xsl:for-each>
                        </xsl:when>
                        <xsl:otherwise>Table of Contents</xsl:otherwise>
                    </xsl:choose>
                </xsl:attribute>
                <span class="expand-button-action-labels">
                    <span id="{$expandActionID}" aria-label="Expand"/>
                    <span id="{$collapseActionID}" aria-label="Collapse"/>
                    <span id="{$pendingActionID}" aria-label="Pending"/>
                </span>
            </xsl:if>
            
            <xsl:apply-templates select="node()" mode="toc-accessibility"/>
        </xsl:copy>
    </xsl:template>    
</xsl:stylesheet>


In my Publishing Template I have linked the above stylesheet on the com.oxygenxml.webhelp.xsl.createNavLinks XSLT Extension Point:

Code: Select all

<xslt>
        <extension file="xsl/toc-ext.xsl" id="com.oxygenxml.webhelp.xsl.createNavLinks"/>
</xslt>
Regards,
Alin

Re: Override sidetoc.xsl aria-label

Posted: Wed Jun 30, 2021 3:15 pm
by ckabstein
Hi Alin,

This works like a charm. Thank you so much for this detailed description! This helps me a lot.

I did not have the slightest idea what to do to make the oxygen:getParameter() function work.

Best regards,
Christina