keyref page numbers

Post here questions and problems related to editing and publishing DITA content.
kwriter
Posts: 18
Joined: Wed Feb 22, 2017 8:04 pm

keyref page numbers

Post by kwriter »

Hello,

Is there a way to add page numbers to keyrefs in the PDF output? How about to xrefs that use text input by the writer instead of pulling the title of the topic?

I have looked through links.xsl and found the insertPageNumberCitation template, and I can see where the text, "on page" gets inserted by the On the page variable in the en.xml file, but I don't see/understand the logic for keyrefs and author-input text.

Thanks.
Radu
Posts: 9058
Joined: Fri Jul 09, 2004 5:18 pm

Re: keyref page numbers

Post by Radu »

Hi,

I'm not sure what you mean by keyrefs and author-input text?
Do you mean a <ph keyref="..."</ph> where the key is defined in the DITA Map and mapped to a keyword?
Or do you mean an xref with a keyref?
For the former, this is not generated as a link.
For the latter, from what I rememeber the page number appears only if you leave the <xref/> empty, once you start adding text to it both the link text and the the page number are no longer computed.
What you can do is to define the link text directly on the keydef:

Code: Select all

<topicref href="topics/introduction.dita" keys="introduction">
<topicmeta>
<linktext>MY CUSTOM TEXT</linktext>
</topicmeta>
</topicref>
and then refer to the key in another topic like:

Code: Select all

<xref keyref="introduction"/>
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
kwriter
Posts: 18
Joined: Wed Feb 22, 2017 8:04 pm

Re: keyref page numbers

Post by kwriter »

Hi Radu,

Sorry for the confusion. I'm actually talking about both xrefs and keyrefs. As you mentioned, when I put custom text into the xref, the page number is not displayed in the output. Is there a way to make it display the page number?

For keyrefs, I don't get a page number at all, regardless of whether the link text is computed or I type text in. Is there a way to display the page number for kerefs in both instances?

Thanks.

Kyla
Radu
Posts: 9058
Joined: Fri Jul 09, 2004 5:18 pm

Re: keyref page numbers

Post by Radu »

Hi Kyla,

So:
As you mentioned, when I put custom text into the xref, the page number is not displayed in the output. Is there a way to make it display the page number?
There is no setting for this right now, I added an issue for this:

https://github.com/dita-ot/dita-ot/issues/2617

But you can probably achieve this behavior if you customize the PDF output with a plugin or a customization folder.
In the XSLT stylesheet:

OXYGEN_INSTALL_DIR/frameworks/dita/DITA-OT2.x/plugins/org.dita.pdf2/xsl/fo/links.xsl

you can search for 1880097, it's the ID of the issue in which the decision was made not to present the page number.
For keyrefs, I don't get a page number at all, regardless of whether the link text is computed or I type text in.
I cannot reproduce this behavior, could you tell me more how the key that you refer to is defined in the DITA Map? The workaround I gave you in the previous post worked for me.
What DITA OT version are you using? Are you using Oxygen's bundled DITA OT or an external one?

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
kwriter
Posts: 18
Joined: Wed Feb 22, 2017 8:04 pm

Re: keyref page numbers

Post by kwriter »

Thanks Radhu,

I think I've found the XSLT template that I need to change to get page numbers for the xrefs with author-entered text. For the keyrefs, I have a couple in my front matter that do not produce page numbers, though the links build fine and work in the output. I am currently using Oxygen 15.1, but will soon upgrade to 18. Is this something that is a result of using the older DITA OT?

The link in my file looks like this:

Code: Select all

<xref keyref="xref_environ_specs"/>
The key in my map looks like this:

Code: Select all

<chapter locktitle="yes" navtitle="CHAPTER 9 Power and Environmental Specifications"
href="nexus_dr/topics/Operator_Chapter_PowerAndEnvironmentalSpecs.dita"
keys="xref_environ_specs"/>
kwriter
Posts: 18
Joined: Wed Feb 22, 2017 8:04 pm

Re: keyref page numbers

Post by kwriter »

The OT version, I believe is 1.8, and it is the one bundled with Oxygen 15.1.
kwriter
Posts: 18
Joined: Wed Feb 22, 2017 8:04 pm

Re: keyref page numbers

Post by kwriter »

Hi Radhu,

I figured out how to turn on page numbers for cross-references where the author has entered the text to display in the output link. I'll post it here in case anyone else needs it.

1. In your customization, add the links.xml file to the fo\xsl directory, and add the appropriate import statement to custom.xml.
2. Set the relative path to the output-message.xsl import statement because you're using the links.xml file in the customization directory or plugin.
3. Find the following code in links.xml

Code: Select all

<xsl:if test="not(@scope = 'external' or @format = 'html') and not($referenceTitle = '') and not($element[contains(@class, ' topic/fn ')])"> 

<!-- SourceForge bug 1880097: should not include page number when xref includes author specified text -->
<xsl:if test="not(processing-instruction()[name()='ditaot'][.='usertext'])">

<xsl:call-template name="insertPageNumberCitation">
<xsl:with-param name="destination" select="$destination"/>
<xsl:with-param name="element" select="$element"/>
</xsl:call-template>

</xsl:if></xsl:if>
4. Comment out the <xsl:if test="not(processing-instruction()[name()='ditaot'][.='usertext'])"> statement leaving only the <xsl:call-template name="insertPageNumberCitation"> statement active:

Code: Select all

<xsl:if test="not(@scope = 'external' or @format = 'html') and not($referenceTitle = '') and not($element[contains(@class, ' topic/fn ')])"> 

<!-- SourceForge bug 1880097: should not include page number when xref includes author specified text -->

<!-- <xsl:if test="not(processing-instruction()[name()='ditaot'][.='usertext'])"> -->

<xsl:call-template name="insertPageNumberCitation">
<xsl:with-param name="destination" select="$destination"/>
<xsl:with-param name="element" select="$element"/>
</xsl:call-template>

<!-- </xsl:if> -->
</xsl:if>
Radu
Posts: 9058
Joined: Fri Jul 09, 2004 5:18 pm

Re: keyref page numbers

Post by Radu »

Hi,

Thanks for posting a more precise sequence of steps.
About this step:
In your customization, add the links.xml file to the fo\xsl directory, and add the appropriate import statement to custom.xml.
You should avoid as possible copying an entire XSLT stylesheet from the base PDF XSLTs to the customization directory. You should directly copy inside the custom.xsl only the XSLT template that you want to override.

There is a best practice for PDF customizations here:

http://www.dita-ot.org/dev/dev_ref/pdf- ... tices.html
Avoid copying entire DITA-OT files into your customization plug-in. When you only copy the attribute sets and templates that you need to override, there is less risk of impact from new features or fixes in the base code, making your code more stable and easier to upgrade between releases.
meaning that if for example a new DITA OT comes out with new changes to templates in the base "links.xsl", you will not benefit of those changes because you have overridden all xsl:templates from the "links.xsl".

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
kwriter
Posts: 18
Joined: Wed Feb 22, 2017 8:04 pm

Re: keyref page numbers

Post by kwriter »

Thanks Radhu.
Post Reply