Custom formatting of XREF output

Post here questions and problems related to editing and publishing DITA content.
ericding
Posts: 2
Joined: Thu Apr 03, 2025 11:46 am

Custom formatting of XREF output

Post 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.
julien_lacour
Posts: 679
Joined: Wed Oct 16, 2019 3:47 pm

Re: Custom formatting of XREF output

Post 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
ericding
Posts: 2
Joined: Thu Apr 03, 2025 11:46 am

Re: Custom formatting of XREF output

Post 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!
chrispitude
Posts: 922
Joined: Thu May 02, 2019 2:32 pm

Re: Custom formatting of XREF output

Post by chrispitude »

Hi Julien,

That is a clever automatic solution!
Post Reply