How to compute the node for href

manojdcoder
Posts: 63
Joined: Thu Oct 29, 2020 12:01 am

How to compute the node for href

Post by manojdcoder » Tue Dec 22, 2020 10:50 pm

When a xref (cross reference) points to a title element, Oxygen doesn't render the content of title.

Document

Code: Select all

<xref href="a1_45845187-1b96-4f91-96d8-7cd07871849f.xml#a1/v461323"/>
a1_45845187-1b96-4f91-96d8-7cd07871849f.xml

Code: Select all

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE concept PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
<concept props="monitor" product="my product" base="Test" rev="4.0" id="a1">
	<title id="v461323">Test Title</title>
</concept>
I managed to extend the default LinkTextResolver for DITA, I'm getting a hit on resolveReference method, I'm able to get the href attribute from the node so far.

I'm trying to understand how may access the document, get the particular element from document by id (a1/v461323) etc., Not able to find any docs on that, any pointers?

Code: Select all

@Override
	public String resolveReference(AuthorNode node) throws InvalidLinkException {
		String text = super.resolveReference(node);
		if (text == "") {
			AuthorElement element = (AuthorElement) node;

			AttrValue attrValue = element.getAttribute(ATTRIBUTE_HREF);
			if (attrValue != null && node.getXMLBaseURL() != null) {
				String hrefValue = attrValue.getValue();
				// How to get the referenced node in HREF?
			}
		}
		return text;
	}

cristi_talau
Posts: 329
Joined: Thu Sep 04, 2014 4:22 pm

Re: How to compute the node for href

Post by cristi_talau » Wed Dec 23, 2020 3:12 pm

Hello,

Our DITALinkTextResolver tries to resolve the text for the same links that are resolved in the published output. For links to title elements, the published output resolves the links but the editor not - I registered an internal issue about this. To properly prioritize this issue I would like to understand how common this case is in your content.

Related to links to other types of elements, they are not resolved in the published output and also not in the editor. Unfortunately, the editor does not have too much API to help you with this use-case. You will have to:
  • Resolve the link to obtain the topic URL. This can be complicated if advanced DITA features are used like keys, key scopes, etc.
  • Fetch the content of the topic from the CMS.
  • Parse the content of the topic.
  • Use the link anchor to identify the target element. There are a number of cases in the DITA specification.
While implementing a solution that works for simple cases should not be complicated. Implementing the full DITA specification is a very complex task.

Best,
Cristian

manojdcoder
Posts: 63
Joined: Thu Oct 29, 2020 12:01 am

Re: How to compute the node for href

Post by manojdcoder » Wed Dec 23, 2020 6:11 pm

We identified the issue with following elements so far,

1. Title
2. Table Row
3. Table Cell

We expected Table Row / Cell to work similar to List Item or Step, where it shows the count of that element form its parent. Parsing the DITA content on our own seems difficult & challenging at this point, so for now we have overridden the dita link resolver to return href value.

cristi_talau
Posts: 329
Joined: Thu Sep 04, 2014 4:22 pm

Re: How to compute the node for href

Post by cristi_talau » Wed Dec 23, 2020 6:45 pm

Hello,

We will fix the "Table" link text in a future release. For links to table cell and table row, does not DITA-OT publishing generate the expected link text? What transformation type are you using? I tested with the PDF output and it did not generate.

Regards,
Cristian

manojdcoder
Posts: 63
Joined: Thu Oct 29, 2020 12:01 am

Re: How to compute the node for href

Post by manojdcoder » Thu Dec 24, 2020 6:54 pm

Hello Cristi,

I'm not referring to the transformation type, but how it renders in the document on the screen.
image.png
image.png (106.26 KiB) Viewed 540 times
In the above screenshot,

1. The first link points to a title, by default it renders empty link
2. The second link points to a table row, by default it renders empty link
3. The third link points to a List Item, by default it renders the count of the list item from its parent, in this case its the third <li> from its parent ol

We wanted to render the title content in case of #1 and display the count of the row from its parent table in case of #2. Since Oxygen doesn't provide any out of the box APIs to access the AuthorElement thats referenced in href, we are simply showing the href value which is better than empty link.

Code: Select all

        @Override
	public String resolveReference(AuthorNode node) throws InvalidLinkException {
		String text = super.resolveReference(node);
		if (text != null && text.isEmpty()) {
			// When referenced content from `href` is empty, render `href` value
			AuthorElement element = (AuthorElement) node;
			AttrValue attrValue = element.getAttribute(ATTRIBUTE_HREF);
			if (attrValue != null) {
				text = attrValue.getValue();
			}
		}
		return text;
	}
image.png
image.png (159.03 KiB) Viewed 540 times

cristi_talau
Posts: 329
Joined: Thu Sep 04, 2014 4:22 pm

Re: How to compute the node for href

Post by cristi_talau » Mon Dec 28, 2020 11:32 am

Hello,

I understand that you want to control how the editor renders the links.

I was trying to say that the editor implements the same behavior as DITA-OT. This way, if people will see a link with no text in the editor, they will understand that the output will also contain an empty link (which is not desirable). As a consequence, they will type their own link text.

This is the reason we are reluctant to change the default link text resolution behavior. I was wondering why imitating the published output rendering is not a good idea for your users.

Best,
Cristian

cristi_talau
Posts: 329
Joined: Thu Sep 04, 2014 4:22 pm

Re: How to compute the node for href

Post by cristi_talau » Fri Mar 05, 2021 12:37 pm

Hello,

I am writing to let you know that we released Oxygen XML Web Author version 23.1 and that now the link text for links to titles are resolved correctly.

For more details about what is new in this version, check out our website: https://www.oxygenxml.com/xml_web_author/whats_new.html .

Best,
Cristian

Post Reply