Page 1 of 1

shorten long weblinks

Posted: Thu Dec 01, 2011 1:09 am
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

Re: shorten long weblinks

Posted: Thu Dec 01, 2011 6:13 pm
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

Re: shorten long weblinks

Posted: Fri Dec 02, 2011 3:59 pm
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

Re: shorten long weblinks

Posted: Fri Dec 02, 2011 6:06 pm
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

Re: shorten long weblinks

Posted: Mon Dec 05, 2011 9:59 am
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