Add metadata from DITA map to menu items in HTML output

tonra
Posts: 11
Joined: Wed Jun 05, 2019 10:39 am
Location: Germany

Add metadata from DITA map to menu items in HTML output

Post by tonra » Thu Aug 15, 2019 12:18 pm

Hi,

I have an XSLT-related question regarding the Oxygen WebHelp Responsive transformation.
I would like to get metadata from a DITA map and integrate it to the side toc navigation's elements (as an attribute).
The HTML part of this has to be done in sidetoc.xsl, I guess. But how can I get the data from the <audience> element in <topicmeta>? Unfortunately, I am not that familiar to XSLT/XPath so that I don't know how to access the DITA map from sidetoc.xsl or tocDitaImpl.xsl. I tried to use the integration of the <shortdesc> element as an example but had no success yet.

Would it also be possible to access the <audience> element in the DITA map from topic.xsl?

Thanks a lot in advance!

Best regards,
Anton

tonra
Posts: 11
Joined: Wed Jun 05, 2019 10:39 am
Location: Germany

Re: Add metadata from DITA map to menu items in HTML output

Post by tonra » Fri Aug 16, 2019 3:10 pm

Hi,

I managed to get the desired metadata. It was a bit tricky to understand the XPath syntax using variables.
This is my approach:

Code: Select all

<xsl:value-of select="toc:topicmeta/toc:audience/@type"/>
(within the xsl template matching xsl:topic).

Unfortunately, there is a problem when I try to get only the metadata from topics at a deeper level. Here is an example:

Code: Select all

<map>
<title></title>
<topicref>
	<topicmeta><audience type="novice"/></topicmeta>
	<topicref>
		<topicmeta><audience type="expert"/></topicmeta>
	</topicref>
</topicref>
</map>
With the XPath command

Code: Select all

map/topicref/topicref/topicmeta/audience/@type
it is possible to get the desired result, namely "expert".

When I try to achieve the same within sidetoc.xsl with

Code: Select all

//toc:toc/toc:topic/toc:topic/toc:topicmeta/toc:audience/@type
I get the @type values from parents and siblings, too. What am I doing wrong?

Best regards,
Anton

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

Re: Add metadata from DITA map to menu items in HTML output

Post by alin » Tue Aug 27, 2019 12:38 pm

tonra wrote:
Fri Aug 16, 2019 3:10 pm

With the XPath command

Code: Select all

map/topicref/topicref/topicmeta/audience/@type
it is possible to get the desired result, namely "expert".

When I try to achieve the same within sidetoc.xsl with

Code: Select all

//toc:toc/toc:topic/toc:topic/toc:topicmeta/toc:audience/@type
I get the @type values from parents and siblings, too. What am I doing wrong?
Hello,

According with this topic https://www.oxygenxml.com/dita/1.3/spec ... adata.html in the DITA 1.3 Specification the <audience> metatdata element cascades to child <topicref> elements. This is why you are obtaining the values from set on the parent elements.

One way to avoid this is to use the <data> metadata element instead of <audience>. For example:

Code: Select all

<data name="audience" value="expert"/>
Moreover, if you would use the @audience profiling attribute instead of the <audience> element in conjunction with a DITAVAL file, the value of the @audience attribute will be automatically transferred in the output. For example:
  • The DITAVAL file - use the passthrough action to let the DITA-OT processor know that the values of the @audience attribute should be transferred in the HTML output:

    Code: Select all

    <val>
        <prop action="passthrough" att="audience"/>
    </val>
    
  • The DITA Map file:

    Code: Select all

    <map cascade="nomerge">
        <title>Passthrough</title>
        <topicref href="topic_1.dita" audience="expert">
            <topicref href="topic_1_1.dita" audience="novice"/>
            <topicref href="topic_1_2.dita" audience="novice"/>
        </topicref>
        <topicref href="topic_2.dita" audience="novice"/>
    </map>
    
Please note that the value of the @audience attribute is also cascaded to the child <topicref> elements. To avoid this you can set the @cascade="nomerge" attribute on the root element of the DITA Map.
The the @audience attribute from the <topicref> element will be transferred as a @data-audience attribute on the corresponding Menu or TOC entry.
This topic in our User Manual describes how use a DITAVAL file with Webhelp Responsive: https://www.oxygenxml.com/doc/versions/ ... ntent.html

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

Post Reply