Hi Natalie,
I see what you are trying to do, by using XSL to modify the incoming element 
and then use apply-templates on the result.  However, that is tricky to do in 
XSL, because the xsl:copy creates what's called a "result tree fragment", which 
is not a node in the document, so you cannot directly apply templates to it.  
It can be converted to a node, but then it loses any context, further 
complicating the process.

I would instead suggest you copy and modify the template named 'simple.xlink' 
from fo/inline.xsl.  That template is used to form the fo:basic-link element 
from any number of DocBook linking elements.  Unfortunately, it is a big 
template because of the variety of linking methods in DocBook, but your change 
is pretty simple.  In your customized template, change this:

       <!-- otherwise it's a URI -->
        <xsl:otherwise>
          <fo:basic-link external-destination="url({$xhref})">
            <xsl:apply-templates select="." mode="simple.xlink.properties"/>
            <xsl:copy-of select="$content"/>
          </fo:basic-link>

to this:

        <!-- otherwise it's a URI -->
        <xsl:otherwise>
          <xsl:variable name="uri">
            <xsl:choose>
              <xsl:when test="$node/@role = 'relative'">
                <xsl:value-of select="concat('http://prefix/', @xlink:href)"/>
              </xsl:when>
              <xsl:otherwise>
                <xsl:value-of select="@xlink:href"/>
              </xsl:otherwise>
            </xsl:choose>
          </xsl:variable>
          <fo:basic-link external-destination="url({$uri})">
            <xsl:apply-templates select="." mode="simple.xlink.properties"/>
            <xsl:copy-of select="$content"/>
          </fo:basic-link>

Bob Stayton
Sagehill Enterprises
[email protected]


From: Natalie Kershaw 
Sent: Monday, September 16, 2013 12:13 PM
To: [email protected] 
Subject: [docbook-apps] Convert a relative file link to a URL in docbook


I am using docbook as a source for HTML and PDF output. In the docbook source, 
I have a series of links which are relative (pointing to javadoc files), which 
is fine for the HTML output because the javadoc files are deployed alongside 
the original document. For the PDF output, I would like to convert these to 
absolute links by way of prepending a URL prefix. Is this possible? I have 
added a 'relative' role to these links and have tried adding a fo customization 
layer:

<xsl:template match="d:link[@role='relative']">
  <xsl:copy>
    <xsl:attribute name="xlink:href">
      <xsl:value-of select="concat('http://prefix/', @xlink:href)"/>
    </xsl:attribute>
  </xsl:copy>
  <xsl:apply-templates select="d:link"/>
</xsl:template>
This seems to half-work in that it does prepend the prefix to the link href, 
but then it does not convert the link element into FO.

Any ideas, or other ways this could be done?

Reply via email to