Page 1 of 1

Custom formatting of XREF output

Posted: Thu Apr 03, 2025 11:57 am
by ericding
I'm using Oxygen 27.1 to create PDF documentation in DITA. When I use an XREF, the PDF output will be something like "Topic title (on page X)".
Normally this is fine, but there are some cases where I would like to put XREFs in a table, and because of space restrictions I don't want the entire topic title and page number as a link. Instead I would like to only have the chapter number of the referenced topic as link text, so the links should look like "X.Y.Z".
Is there a way I could create an outputclass for these XREFs that will change the text used in the output? I've been successfull in creating an outputclass to change the formatting of the link, but not the text.

Re: Custom formatting of XREF output

Posted: Thu Apr 03, 2025 12:52 pm
by julien_lacour
Hello,

You can use outputclass but you could also match directly xrefs inside tables:

Code: Select all

*[class ~= "topic/table"] *[class ~= "topic/xref"][type = "topic"][href] {
  content: target-counters(attr(href), chapter-and-sections, ".");
}
The rule above override the default content showing the target title and only displays the target chapter number.
If you want to remove the "(on page X)" label too, you can add this rule to the previous one:

Code: Select all

*[class ~= "topic/table"] *[class ~= "topic/xref"][href]:after {
  content: none;
}
Regards,
Julien

Re: Custom formatting of XREF output

Posted: Thu Apr 03, 2025 5:17 pm
by ericding
This works beautifully! I had to expand it a bit to also match concept, task and reference topics, but once that was done the solution worked as desired.
Thank you for the help!

Re: Custom formatting of XREF output

Posted: Sat Apr 05, 2025 2:42 pm
by chrispitude
Hi Julien,

That is a clever automatic solution!