shorten long weblinks

Having trouble installing Oxygen? Got a bug to report? Post it all here.
Boreas
Posts: 86
Joined: Wed Feb 09, 2011 10:43 pm

shorten long weblinks

Post by Boreas »

Hello,

I use weblinks in my documents but the link that is displayed is very long and ugly. I was wondering if there was a way to shorten the link so that it displays only a 2 or 3 word link.
I know that bitly and Google links does it, but I cannot use them because, well because... 8-)
I was wondering if there was an Oxygen feature, or trick that could do it.(an attribute perhaps?)

thanks
alex_jitianu
Posts: 1009
Joined: Wed Nov 16, 2005 11:11 am

Re: shorten long weblinks

Post by alex_jitianu »

Hello,

You can edit the CSS so that a shorter path is displayed for links. For DITA the CSS where you should intervene is {oxygenInstallDir}/frameworks/dita/css_classed/topic.css. For an XREF element the rule that should be modified is:

Code: Select all

*[class~="topic/link"][href]:before,
*[class~="topic/xref"][href]:before {
content:url("../img/link.png") "[" attr(href) "]";
}
You can use regular expressions to shorten the path. Something like this:

Code: Select all

*[class~="topic/link"][href]:before,
*[class~="topic/xref"][href]:before {
content:url("../img/link.png") "[" oxy_replace(attr(href), '^(.*?([^/]*/)+?)?([^/]*)$', '.../$2$3', true) "]";
}
I've also logged an issue on our issue tracking tool to add an CSS extension function that will receive as input a path and a maximum length and will return a path that has been shortened to respect that limit. This way a future version of Oxygen will provide this functionality out of the box.

Regards,
Alex

Alex Jitianu
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Boreas
Posts: 86
Joined: Wed Feb 09, 2011 10:43 pm

Re: shorten long weblinks

Post by Boreas »

hello,

heum, I did not succeed.I changed the topic.css file as you suggested.I do have to admit that I did it blindly. I am totally CSS ignorant. 8-)
Then in my xml file I inserted the xref using the xref element in the element list. Then I generated the webhelp. and the link was there, functional, but still very long.
I am probably missing something, very insignificant, but what am I doing wrong?

thanks again for your help.

Carole
alex_jitianu
Posts: 1009
Joined: Wed Nov 16, 2005 11:11 am

Re: shorten long weblinks

Post by alex_jitianu »

Hello,

I was under the impression that your question referred to displaying the XML in oXygen Author page so I gave an answer for that. My mistake. You are actually referring to the html output of an WebHelp transformation? If that is the case, you should probably intervene inside the XSL stylesheets used for WebHelp.
The template that processes XHREF is found in {oxygenInstallDir}/frameworks/dita/DITA-OT/xsl/xslhtml/rel-links.xsl:

Code: Select all

<xsl:template match="*[contains(@class,' topic/xref ')]" name="topic.xref">
There are a lot of branches there, processing different types of XREFs, but for an XREF like

Code: Select all

<xref href="http://www.oxygenxml.com/forum/topic6490.html" format="html" scope="external"/>
it will go through line 77

Code: Select all

<xsl:when test="*[not(contains(@class,' topic/desc '))]|text()">
Following the xref element presented above, to output just the last part of its href you could replace line 78:

Code: Select all

<xsl:apply-templates select="*[not(contains(@class,' topic/desc '))]|text()"/>
with:

Code: Select all


<xsl:call-template name="getHrefName">
<xsl:with-param name="href">
<xsl:apply-templates select="*[not(contains(@class,' topic/desc '))]|text()"/>
</xsl:with-param>
</xsl:call-template>
where the getHrefName template should be declared like:

Code: Select all


<xsl:template name="getHrefName">
<xsl:param name="href"/>
<xsl:choose>
<xsl:when test="contains($href, '/')">
<xsl:call-template name="getHrefName">
<xsl:with-param name="href" select="substring-after($href, '/')"/>
</xsl:call-template>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$href"/>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
Template getHrefName can be edited to obtain a different representation if required. Also, the same approach can be used on other branches (<xsl:when) if needed.

Regards,
Alex
alex_jitianu
Posts: 1009
Joined: Wed Nov 16, 2005 11:11 am

Re: shorten long weblinks

Post by alex_jitianu »

Hello,

As an alternative, you could enter a shorter link description inside the XREF element. Instead of an empty element, just use :

Code: Select all

<xref href="http://www.oxygenxml.com/forum/topic6490.html" format="html" scope="external">topic6490.html</xref>
.

Regards,
Alex
Post Reply