How to transmit an attribute value from a topicref to a topic attribute

Post here questions and problems related to editing and publishing DITA content.
gbv34
Posts: 105
Joined: Thu Jan 20, 2022 12:36 pm

How to transmit an attribute value from a topicref to a topic attribute

Post by gbv34 »

Hello!
I have topicrefs in a ditamap using outputclass with specific values.
I'm trying to retrieve the value of the outputclass attribute and copy them within the referenced topics.

Example with a chunked topic:

Code: Select all

<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="UTF-8">
<meta name="copyright" content="(C) Copyright 2022">
<meta name="DC.rights.owner" content="(C) Copyright 2022">
<meta name="DC.type" content="topic">
<meta name="DC.format" content="HTML5">
<meta name="DC.identifier" content="t-1">
<link rel="stylesheet" type="text/css" href="commonltr.css">
<title>1</title>
</head>

<body>
<main role="main">
<article role="article" aria-labelledby="ariaid-title1">
<article class="nested0" aria-labelledby="ariaid-title1" CUSTOM-ATTRIBUTE="HERE IS THE VALUE PROVIDEDwithin an OUTPUTCLASS from the map " id="t-1">
    <h1 class="title topictitle1 h1" id="ariaid-title1">1</h1>
    <div class="body">
        <p class="p"></p>
    </div>
<article class="topic nested1" aria-labelledby="ariaid-title2" CUSTOM-ATTRIBUTE="HERE IS THE VALUE PROVIDEDwithin an OUTPUTCLASS from the map "  id="t-2">
    <h2 class="title topictitle2 h2" id="ariaid-title2">2</h2>
    <div class="body">
        <p class="p"></p>
    </div>
</article></article></main></body></html>
So my question is to determine from which xslt template I should look at to retrieve the value of the outputclass in the map and copy it in the topics?
------
Gaspard
Radu
Posts: 9091
Joined: Fri Jul 09, 2004 5:18 pm

Re: How to transmit an attribute value from a topicref to a topic attribute

Post by Radu »

Hi,

The XSLTs stylesheets applied on each DITA topic to produce its HTML equivalent do not have direct access to the DITA Map contents, so this is not straightforward.
I assume in this case you could create a DITA OT plugin which has a custom XSLT. The custom XSLT receives a path to the temporary files folder from which it could load the DITA Map using the document() XSLT function.
Maybe similar to my DITA Open Toolkit plugin here:
https://github.com/oxygenxml/dita-embed ... mathml.svg
The plugin.xml contributes an extra XSLT stylesheet:

Code: Select all

  <feature extension="dita.xsl.html5" value="customXHTML.xsl" type="file"/>
and there is a parameters file which contributes a "ditaTempDir" parameter used later in the styleshet:

Code: Select all

 <feature extension="dita.conductor.html5.param" value="localFunctionsParams.xml" type="file"/>
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Radu
Posts: 9091
Joined: Fri Jul 09, 2004 5:18 pm

Re: How to transmit an attribute value from a topicref to a topic attribute

Post by Radu »

Some more details about this particular case of reading the DITA Map contents from the XSLT used to publish individual topics:

If you look in this build file "plugins/org.dita.html5/build_dita2html5.xml" at the ANT target named "html5.topics.common" this parameter is passed as a parameter to the XSLT stylesheet:

Code: Select all

    <param name="input.map.url" expression="${html5.map.url}" if:set="html5.map.url"/>
so you probably just need to declare it in the XSLT and you will be able to use its value like the "plugins/org.dita.html5/xsl/nav.xsl" does:

Code: Select all

  <xsl:param name="input.map.url" as="xs:string?"/>
 
  <xsl:variable name="input.map" as="document-node()?">
    <xsl:apply-templates select="document($input.map.url)" mode="normalize-map"/>
  </xsl:variable>
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
gbv34
Posts: 105
Joined: Thu Jan 20, 2022 12:36 pm

Re: How to transmit an attribute value from a topicref to a topic attribute

Post by gbv34 »

Thanks Radu!

That was very helpful and I succeeded in my task.
I declared the following feature extensions in my plugin.xml

Code: Select all

  <feature extension="dita.conductor.html5.param" file="buildHtml5Param.xml"/>
  <feature extension="dita.conductor.html5.toc.param" file="buildHtml5Param.xml"/>
Then, I created a param in the linked XML file

Code: Select all

<?xml version="1.0" encoding="UTF-8"?>
<params xmlns:if="ant:if">
    <param name="input.map.url" expression="${html5.map.url}" if:set="html5.map.url"/>
</params>
At last, I was able to call information from the map and insert (in my case within the topics. I needed to access the value of an attribute).

Code: Select all

<xsl:param name="input.map.url" as="xs:anyURI" required="yes"/>

  <!-- map URL -->
    <xsl:param name="input.map.url" as="xs:anyURI" required="yes"/>
    <!-- map document -->
    <xsl:variable name="mapDoc" as="document-node()" select="doc($input.map.url)"/>

    <xsl:template match="*[contains(@class, ' topic/topic ')]" mode="child.topic" name="child.topic">
        <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="nested{$nestlevel}">
            <xsl:attribute name="aria-labelledby">
                <xsl:apply-templates select="*[contains(@class, ' topic/title ')]"
                    mode="return-aria-label-id"/>
            </xsl:attribute>
            <xsl:if test="contains($attributeValue, 'tabbed-title=')">
                <xsl:attribute name="myNewClassHere">
                    <xsl:value-of
                        select='substring-before(substring-after($attributeValue, "&apos;"), "&apos;")'
                    />
                </xsl:attribute>
            </xsl:if>
            <xsl:call-template name="gen-topic">
                <xsl:with-param name="nestlevel" select="$nestlevel"/>
            </xsl:call-template>
        </article>
    </xsl:template>
        
        
------
Gaspard
Radu
Posts: 9091
Joined: Fri Jul 09, 2004 5:18 pm

Re: How to transmit an attribute value from a topicref to a topic attribute

Post by Radu »

Great, thanks for posting the complete solution for this.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply