modifying the OLink dialog

steve.cuzner
Posts: 64

modifying the OLink dialog

Fri Jul 24, 2015 8:58 pm

Is there a way to modify what the OLink dialog outputs for a link to implement docbook universal linking? For example, I can create a link with the dialog that looks like

Code: Select all

<olink targetdoc="targets.xml" targetptr="section_njd_lv5_4r">the section
                    called “With No CDATA Content”</olink>


I would like the same link output using universal linking attributes:

Code: Select all

<link xlink:role="http://docbook.org/xlink/role/olink" xlink:href="targets.xml#section_njd_lv5_4r">the section
                    called “With No CDATA Content”</link>


The dialog itself works fine as in, I just need to intercept the data collected from it and add the markup that I need.
radu_pisoi
Posts: 302
Location: Craiova

Re: modifying the OLink dialog

Mon Jul 27, 2015 2:25 pm

Hi,

You are right. If you are using DocBook version 5 or later, then you can use other inline elements as olinks. DocBook 5 supports universal linking, which means it permits xlink:href attributes on most elements to create a link from the current element to some target. http://www.sagehill.net/docbookxsl/Db5T ... nivLinking

A possible solution could be to add a checkbok in the 'Insert OLink' dialog that specifies if XLink attributes will be used when adding new cross references.

I have registered this improvement in our issue tracking system to be resolved in a future oXygen version.
Radu Pisoi
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
steve.cuzner
Posts: 64

Re: modifying the OLink dialog

Mon Jul 27, 2015 4:22 pm

Is there a current API event that I can intercept after the user hits the insert button and before the actual insertion where I can interrupt the flow, gather the target doc and target ptr and insert my own link tags? The alternative is to reinvent the entire olink dialog which seems cumbersome. but if that is the case, are there any pointers you could provide concerning how you are creating the tree view widgets with the document content of the target.db files?

Steve
radu_pisoi
Posts: 302
Location: Craiova

Re: modifying the OLink dialog

Mon Jul 27, 2015 4:58 pm

There is a way to customize/convert the markup added by the Insert OLink action by applying an additional stylesheet over the inserted element.

This is possible by creating a compound Author action (based on ExecuteMultipleActionsOperation) that:
* first it executes the old 'Insert OLink' action that inserts the olink element;
* afterwards, it executes another action (based on XSLTOperation) that executes an XSLT transformation to convert the previously inserted olink element to a link element with XLink attributes.

I have created a sample framework/document type that extends the Docbook 5 document type (document type extensions are supported starting with Oxygen version 16.1). This extension adds a new 'Insert OLink with XLink attributes' action that is available on toolbal near the 'Insert Olink' action.

To use this custom document type please download and unzip the Docbook extension archive in the 'oxygen_install_dir/frameworks' folder.

Please let me know if this document type extension resolve your use case.
Radu Pisoi
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
steve.cuzner
Posts: 64

Re: modifying the OLink dialog

Tue Jul 28, 2015 3:58 pm

Thanks you so much for the code, Radu. Elegant and simple with no performance hit. Wonderful solution.

Steve
steve.cuzner
Posts: 64

Re: modifying the OLink dialog

Tue Jul 28, 2015 7:54 pm

One small issue I've found: if you hit cancel button, any links and the surrounding element are deleted (leaving the text). For example, I positioned the cursor in a para tag inside an abstract tag. If I open the new dialog, then hit cancel, I'm left with the para contents directly inside the abstract element (para markup deleted). If there is link markup, actually any markup such as emphasis, the markup is deleted. The solution was to add the identity transform template to the convert_olink:

Code: Select all


    <xsl:template match="@*|node()">
        <xsl:copy>
            <xsl:apply-templates select="@*|node()"/>
        </xsl:copy>
    </xsl:template>


This does bring up an interesting issue. Since the stylesheet is acting on root (/) of the current element, which is the container of the newly inserted element, the transform is acting the content of that element which may result in the transform acting on elements that you don't intend. Is there a way to limit the scope to the newly inserted element?

Steve
radu_pisoi
Posts: 302
Location: Craiova

Re: modifying the OLink dialog

Wed Jul 29, 2015 10:08 am

steve.cuzner wrote:Is there a way to limit the scope to the newly inserted element?


The solution is to add an activation condition (self::*:olink) for the Convert OLink action (convert.olink). To do this you have to edit the Docbook 5 - Extension framework and then find/edit the Convert OLink action (select Author tab and then Actions tab).

In the Action dialog, find the When this XPath expression is true label and set the XPath to 'self::*:olink'. This will restrict/limit the scope of the action only to the olink elements.

See related documentation topics:
Radu Pisoi
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Return to “DocBook”

Who is online

Users browsing this forum: No registered users and 0 guests