Responsive Webhelp: include bookmap xml:lang value to footer of main page

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

Responsive Webhelp: include bookmap xml:lang value to footer of main page

Post by steinbacherGE » Fri Jul 26, 2019 9:59 pm

How can I add the bookmap xml:lang value to footer of a Responsive Webhelp main page (index.html)?

I'm working in this file ..\xsl\mainFiles\customFooter.xsl

This value shows up correctly in all of my topic footers, but not the main index.html page.

<xsl:value-of select="document($windows_inputMap)/bookmap/@xml:lang"/>

Any suggestions?

Thanks,

Leroy

alin
Site Admin
Posts: 162
Joined: Thu Dec 24, 2009 11:21 am

Re: Responsive Webhelp: include bookmap xml:lang value to footer of main page

Post by alin » Wed Jul 31, 2019 4:32 pm

Hello,

You can add custom HTML content in the WebHelp Responsive output by inserting it in a well-formed XML file that will be referenced in the transformation (either from an Oxygen Publishing Template or using one of the HTML fragment parameters).
The XML file can use WebHelp macros, which are variables that will be expanded when the content of the HTML fragment file will be copied in the final output.
In your case, you can use the map-xpath macro to retrieve the value of the xml:lang attribute from the map root element.
For example the content of the XML file can look like this:

Code: Select all

<div  xmlns:whc="http://www.oxygenxml.com/webhelp/components">
    Publication Language: <b><whc:macro value="${map-xpath(/*/@*:lang)}"/></b>
</div>
In order to include the above content in your publication footer section you should reference the path of the file using the webhelp.fragment.footer transformation parameter.
You can find more details here: https://www.oxygenxml.com/doc/versions/ ... -html.html

Regards,
Alin
Alin Balasa
Software Developer
<oXygen/> XML Editor
http://www.oxygenxml.com

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

Re: Responsive Webhelp: include bookmap xml:lang value to footer of main page

Post by steinbacherGE » Tue Jan 21, 2020 9:36 pm

Thanks for the information. I got this to work, but if the parent map doesn't have an xml:lang attribute the defualt value (en) isn't included.
no-lang.png
no-lang.png (4.06 KiB) Viewed 616 times
Is there a way to show the default value (en) if the xml:lang attribute is empty?

Or, if there is no xml:lang value, can the entire HTML fragment just be ignored so there is no "Publication Language:" at all?

Thanks,

Leroy

alin
Site Admin
Posts: 162
Joined: Thu Dec 24, 2009 11:21 am

Re: Responsive Webhelp: include bookmap xml:lang value to footer of main page

Post by alin » Fri Jan 24, 2020 4:33 pm

Hello,
Is there a way to show the default value (en) if the xml:lang attribute is empty?
You can use the following content in the HTML fragment file:

Code: Select all

<div  xmlns:whc="http://www.oxygenxml.com/webhelp/components">
    Publication Language: <b><whc:macro value="${map-xpath(if (/*/@*:lang) then /*/@*:lang else 'en')}"/></b>
</div>
Regards,
Alin
Alin Balasa
Software Developer
<oXygen/> XML Editor
http://www.oxygenxml.com

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

Re: Responsive Webhelp: include bookmap xml:lang value to footer of main page

Post by steinbacherGE » Fri Feb 07, 2020 12:19 am

This works great. Thanks!

:D

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

Re: Responsive Webhelp: include bookmap xml:lang value to footer of main page

Post by steinbacherGE » Thu Feb 20, 2020 12:18 am

Now that I have the xml:lang value in the footer I would also like to use a whc:macro to add the revision number from /bookmap/bookmeta/publisherinformation/published/revisionid. I would also like to pull in a string value for "Revision" which I already have translated for all languages. The problem is, for certain languages (hu, kk, lv), the revision number comes before the "Revision" string.

I've gotten a good start on this, but I think my code may be more complicated than it needs to be.

Code: Select all

<div class="after-body" xmlns:whc="http://www.oxygenxml.com/webhelp/components">
Publication Language: <whc:macro value="${map-xpath(if (/*/@*:lang) then /*/@*:lang else 'en')}"/><br/>
<whc:macro value="${map-xpath(if ((/*/@*:lang='hu') or (/*/@*:lang='kk') or (/*/@*:lang='lv')) then /bookmap/bookmeta/publisherinformation/published/revisionid else '')}"/><whc:macro value="${i18n(Revision)}"/>
<whc:macro value="${map-xpath(if ((not(/*/@*:lang='hu' or /*/@*:lang='kk' or /*/@*:lang='lv'))) then /bookmap/bookmeta/publisherinformation/published/revisionid else '')}"/>
</div>
My other problem is the string for Revision still shows up even if the /bookmap/bookmeta/publisherinformation/published/revisionid element is empty.

revisionid.png
revisionid.png (4.22 KiB) Viewed 398 times


Is there a way to check for a value in the revisionid element before pulling in the "Revision"string?

I'm also wondering if there is a simpler way to change the order for certain langauges? I'm not sure what all is allowed in the whc:macro syntax.

I looked into creating a wh-macro-extension, but I wonder if that is needed for this problem.

Thanks,

Leroy

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

Re: Responsive Webhelp: include bookmap xml:lang value to footer of main page

Post by steinbacherGE » Fri Feb 21, 2020 1:01 am

I figured out a way to handle this using an XSLT extension.

I defined a variable for the xsl.dita2webhelp XSLT extension.

Code: Select all

<xsl:variable name="lang" select="/*/@*:lang"/>
But it didn't work for main, search and IndexTerm pages.

I found $WEBHELP_DITAMAP_URL in the map-xpath macro template (macroExpander.xsl) and used it instead for the non-topic pages.

Code: Select all

<xsl:param name="WEBHELP_DITAMAP_URL"/>
<xsl:variable name="lang" select="document($WEBHELP_DITAMAP_URL)/*/@*:lang"/>
Here is the xsl that I used to get this to work.

Code: Select all

<xsl:if test="$toc/*:topicmeta[1]/*:publisherinformation/*:published/*:revisionid[1]">
                <span>
                    <xsl:choose>
                        <xsl:when test="$lang = 'hu' or $lang = 'kk' or $lang = 'lv'">
                            <xsl:apply-templates
                                select="$toc/*:topicmeta[1]/*:publisherinformation/*:published/*:revisionid[1]"
                                mode="footer-custom"/>
                            <xsl:call-template name="getWebhelpString">
                                <xsl:with-param name="stringName" select="'Revision'"/>
                            </xsl:call-template>
                        </xsl:when>
                        <xsl:otherwise>
                            <xsl:call-template name="getWebhelpString">
                                <xsl:with-param name="stringName" select="'Revision'"/>
                            </xsl:call-template>
                            <xsl:apply-templates select="$toc/*:topicmeta[1]/*:publisherinformation/*:published/*:revisionid[1]" mode="footer-custom"/>
                        </xsl:otherwise>
                    </xsl:choose>
                </span>
                <xsl:text> | </xsl:text>
            </xsl:if>
So what is the prefered method? Using wh:macro in a XML fragment, or writing a custom XSLT extension?

What are the limits of using conditional expressions with wh:macros? Can you provide some more examples of the proper way to use if and if(not)?

My guess is a wh:macro is easier to use for basic customization, but for more complex conditions, an XSLT extension will work better.

Can you provide some additional information on example use cases for each?

Thanks,

Leroy

alin
Site Admin
Posts: 162
Joined: Thu Dec 24, 2009 11:21 am

Re: Responsive Webhelp: include bookmap xml:lang value to footer of main page

Post by alin » Wed Feb 26, 2020 10:36 am

Hello,

The Macro Component can be used to execute a single XPath expression. There is no limit on how complex the expression is.
My guess is a wh:macro is easier to use for basic customization, but for more complex conditions, an XSLT extension will work better.
Yes, you are right.
It was developed as an workaround for XSLT extensions in order to cover basic use cases when you needed to extract a piece of information from the source document and output it in the HTML files.
You can find several examples of Publishing Templates in this repository: https://github.com/oxygenxml/oxygen-pub ... /templates

Regards,
Alin
Alin Balasa
Software Developer
<oXygen/> XML Editor
http://www.oxygenxml.com

Post Reply