Page 1 of 1

Need a refactoring to make navtitle match the topic title - Version 17.1

Posted: Mon Mar 18, 2019 8:46 am
by Sathya
Hi team,
Would like to know if we have a method to update navtitle with the topic title.

Re: Need a refactoring to make navtitle match the topic title - Version 17.1

Posted: Mon Mar 18, 2019 11:46 am
by Radu
Hi Sathya,

Newer versions of Oxygen (for example Oxygen 18.1 and newer) have in the Preferences->"DITA" page a special section where you can choose to automatically set the navtitle to the topic title when using our actions to insert topic references.

With Oxygen 17.1 you could create a custom XML Refactoring action based on XSLT which would be applied on the DITA Map, for each topicref it would extract the title from the reference and set the @navtitle attribute to that value:

https://www.oxygenxml.com/doc/versions/ ... tions.html

A refactoring XSLT stylesheet for this would look something like:

Code: Select all

<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
exclude-result-prefixes="xs"
version="2.0">
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*"/>
</xsl:copy>
</xsl:template>

<!-- Get topic title and use it to set navtitle on topicref -->
<xsl:template match="topicref[@href]">
<xsl:copy>
<xsl:apply-templates select="@* except @navtitle"/>
<xsl:attribute name="navtitle"><xsl:value-of select="document(@href)/*/title"/></xsl:attribute>
<xsl:apply-templates select="node()"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Regards,
Radu

Re: Need a refactoring to make navtitle match the topic title - Version 17.1

Posted: Thu Mar 28, 2019 8:44 am
by Sathya
Thanks so much Radu. I created an operation description file. The refactoring operation works fine.

Re: Need a refactoring to make navtitle match the topic title - Version 17.1

Posted: Thu Oct 27, 2022 7:12 pm
by craigcharlie
Hi Radu,

I really appreciate this solution, thanks.
However, I'm seeing an issue in implementation. (Note, in case this is relevant - I'm trying to refactor topics from a Tridion Docs repository.)
I need to refactor not only base DITA topic types, but also topics from the msgRef specialization. So, I am using code like this:

Code: Select all

<xsl:value-of select="document(@href)/*/*[contains(@class, 'topic/title')]/normalize-space()"/>
However, I am facing these problems:
  • the xpath only selects info from base DITA topic types, ie not msgRef. For example, if I use document(@href)//msgId/normalize-space(), nothing is selected
  • using *[contains(@class, 'topic/title')] as a selector does not seem to work as expected. This selector only seems to work if I edit the class attribute manually to add "topic/title" - ie, specifically hardcoding the class, instead of depending on values inferred from the DITA DTD. Of note, I have also verified the same behavior with Oxygen's OOTB sample DITA - eg, flowers.ditamap.
Note, if I select the */title node, per your original examples, titles for the base DITA topic types are getting selected correctly.

Appreciate any advice you can give. Note, I'm currently using Oxygen on a trial basis, as I'm evaluating bringing it into our company for use in tech writing.
thanks,
Charlie

Re: Need a refactoring to make navtitle match the topic title - Version 17.1

Posted: Fri Oct 28, 2022 8:36 am
by Radu
Hi Charlie,

This forum thread is from 6 years ago, ideally in such cases you can start a new one.
So your use case is the same, right? Synchronize the navtitle inside the DITA Map with the title defined inside the topic?
How about if you remove all navtitles from the DITA Map instead? Oxygen does not need them for anything, the publishing engine also does not need them for anything.

About your questions:
the xpath only selects info from base DITA topic types, ie not msgRef. For example, if I use document(@href)//msgId/normalize-space(), nothing is selected
I do not know the structure of the "msgRef" topic type, it is not a base DITA topic type so I assume it's a specialization of the DITA DTDs made either by the CMS or specific to your company. Can you post a small example with how the msgRef topic looks like inside?
If you open that topic in Oxygen, you can use Oxygen's "Xpath" toolbar to run queries like "//msgId/normalize-space()", do those queries return anything?
using *[contains(@class, 'topic/title')] as a selector does not seem to work as expected. This selector only seems to work if I edit the class attribute manually to add "topic/title" - ie, specifically hardcoding the class, instead of depending on values inferred from the DITA DTD. Of note, I have also verified the same behavior with Oxygen's OOTB sample DITA - eg, flowers.ditamap.
Indeed Oxygen XML refactoring actions do not take the DTD declaration and default attribute values into account, so you need to match the element name and cannot match it by the default @class attribute value specified in the DTDs.

Regards,
Radu

Re: Need a refactoring to make navtitle match the topic title - Version 17.1

Posted: Thu Nov 03, 2022 8:27 pm
by craigcharlie
Thanks for the reply Radu!
If I use "//msgId/normalize-space()" in the xpath toolbar, it does return the expected result. However the refactoring operation doesn't "see it" - it only seems able to access core DITA elements.

Note that I have been trying to add DTDs via Preferences > XML > Catalog - I added a reference to the Tridion Docs catalog.xml, and unchecked "Use default catalog", but the refactoring statement "document(@href)//msgId/normalize-space()" doesn't return anything. Conversely, "document(@href)//title/normalize-space()" does work correctly, and the title of the concept is written into the map navtitle.

It seems to me that the Refactoring functionality must be relying on the OOTB DTDs, rather than the ones installed by the Tridion Docs plugin. Do you have any information on how I can make those DTDs available to the Refactoring operation?

Re: Need a refactoring to make navtitle match the topic title - Version 17.1

Posted: Fri Nov 04, 2022 9:01 am
by Radu
Hi Charlie,

Does the XML refactoring operation report any error when you run it?
In general when using the document(..) function to load an XML document, if that XML document has a DTD reference, the XSLT processor needs the DTD to be available in order to load the XML document. So it's good that you added your custom XML catalog to the "Preferences > XML > Catalog" page. You should have left the "Use default catalog" checked as it's not an either/or case, the default catalog will be used along with your extra added XML catalogs.
Other than that, if we cannot get to the bottom of this and you are willing to send us some samples to reproduce the problem (support@oxygenxml.com) we can try to look a bit into this on our side.

Regards,
Radu

Re: Need a refactoring to make navtitle match the topic title - Version 17.1

Posted: Tue Nov 08, 2022 9:26 pm
by craigcharlie
Hi Radu,
Thanks very much for your reply. It's clear more work would be needed to get refactoring working.
On further investigation, I'm actually seeing all expected titles in Map Manager but not Author Mode. I will start a new thread to ask a question about this - my expectation is that the Author Mode behavior should be the same.
thanks,
Charlie