[xsl] Processing Links With Relative or Absolute Paths

Subject: [xsl] Processing Links With Relative or Absolute Paths
From: Robert Siebens <telehodown@xxxxxxxxx>
Date: Wed, 7 Oct 2009 10:52:12 -0700 (PDT)
Ibm new to XSLT and XSL:FO and apologize for asking such a basic question in
this list. I looked around on the XSL archive
(http://www.biglist..com/lists/xsl-list/archives/), Dave Pawson's site and
elsewhere  and wasn't able to find what I needed.

I am confused about how to handle links containing paths to the file system
such as the relative <a href="../system/companies/logic_preferences.htm"> or
the absolute <a
href="c:\project_files\system\companies\logic_preferences.htm">.  I am
combining many XML files into a PDF (through FOP-0.95). Ibve found code
samples that help me process other types of links such as internal anchors
(like <a href="#My_Big_Anchor">),as well as to process external links
containing URIs. Each of these makes use of a source and target. Where I'm
stumped is how to create a source and target when the "href" points to a file
in the file system (either relative or absolute paths). Perhaps that's not the
technique to handle this?

When I include the snippet below in my XSL stylesheet, it treats the "href"
attributes containing directory paths as external links and creates a link in
my PDF to the actual file outside the document. What's the XSLT trick for
handling this third type of link that should point inside the document?

Here is an example of what I'm doing so far:

CODE (for file with two types of anchor tags)
<?xml version="1.0" encoding="utf-8"?>

<p>This file has an anchor tag pointing to the <a
href="../system/companies/logic_preferences.htm">file</a> below. But when FOP
combines my XML files, Ibm not sure how to set up a link from one file to
the other via the relative path. Even if I change this to an absolute path, it
points to the XML file in the file system--not to the location of the content
in the combined PDF.</p>

<p>This file also has an internal anchor to another <a
href=#My_Same_Page_Anchor>item</a> on the same page.</p>

<p>Here is the <a name=bMy_Same_Page_Anchorb>target</a> of the anchor from
the same page. This type of link works without a hitch in my FOP.</p>


CODE (for file that is the target of the anchor tag in the file above)
<?xml version="1.0" encoding="utf-8"?>

<p>This file is the target of the anchor tag in the file above. </p>

CODE (Stylesheet code to processes internal links flagged by the b#b as
well as external links using URIs:)
<xsl:template match="a">
    <xsl:when test="@name">
      <xsl:if test="not(name(following-sibling::*[1]) = 'h1')">
        <fo:block line-height="0" space-after="0pt"
          font-size="0pt" id="{@name}"/>
    <xsl:when test="@href">
      <fo:basic-link color="blue">
          <xsl:when test="starts-with(@href, '#')">
            <xsl:attribute name="internal-destination">
              <xsl:value-of select="substring(@href, 2)"/>
            <xsl:attribute name="external-destination">
              <xsl:value-of select="@href"/>
        <xsl:apply-templates select="*|text()"/>
      <xsl:if test="starts-with(@href, '#')">
        <xsl:text> on page  </xsl:text>
        <fo:page-number-citation ref-id="{substring(@href, 2)}"/>

What should I add to process this third type of link that contains a relative
or absolute path?



Current Thread