1<?xml version="1.0"?>
2<!--
3   Copyright (c) 2002 Douglas Gregor <doug.gregor -at- gmail.com>
4
5   Distributed under the Boost Software License, Version 1.0.
6   (See accompanying file LICENSE_1_0.txt or copy at
7   http://www.boost.org/LICENSE_1_0.txt)
8  -->
9<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
10                xmlns:suwl="http://nwalsh.com/xslt/ext/com.nwalsh.saxon.UnwrapLinks"
11                exclude-result-prefixes="suwl"
12                version="1.0">
13
14<!-- Import the HTML chunking stylesheet -->
15<xsl:import
16    href="http://docbook.sourceforge.net/release/xsl/current/html/xref.xsl"/>
17
18
19<xsl:template name="adjust-url">
20    <xsl:param name="target"/>
21    <xsl:param name="context" select="."/>
22
23    <xsl:choose>
24        <xsl:when test="contains($target, ':')">
25          <xsl:value-of select="$target"/>
26        </xsl:when>
27        <xsl:otherwise>
28          <xsl:call-template name="href.target.relative">
29            <xsl:with-param name="target" select="$target"/>
30          </xsl:call-template>
31        </xsl:otherwise>
32    </xsl:choose>
33
34</xsl:template>
35
36
37<xsl:template match="ulink" name="ulink">
38  <xsl:variable name="link">
39    <a>
40      <xsl:if test="@id">
41        <xsl:attribute name="name">
42          <xsl:value-of select="@id"/>
43        </xsl:attribute>
44      </xsl:if>
45      <xsl:attribute name="href">
46        <xsl:call-template name="adjust-url">
47          <xsl:with-param name="target" select="@url"/>
48        </xsl:call-template>
49      </xsl:attribute>
50      <xsl:if test="$ulink.target != ''">
51        <xsl:attribute name="target">
52          <xsl:value-of select="$ulink.target"/>
53        </xsl:attribute>
54      </xsl:if>
55      <xsl:choose>
56        <xsl:when test="count(child::node())=0">
57          <xsl:value-of select="@url"/>
58        </xsl:when>
59        <xsl:otherwise>
60          <xsl:apply-templates/>
61        </xsl:otherwise>
62      </xsl:choose>
63    </a>
64  </xsl:variable>
65
66  <xsl:choose>
67    <xsl:when test="function-available('suwl:unwrapLinks')">
68      <xsl:copy-of select="suwl:unwrapLinks($link)"/>
69    </xsl:when>
70    <xsl:otherwise>
71      <xsl:copy-of select="$link"/>
72    </xsl:otherwise>
73  </xsl:choose>
74</xsl:template>
75
76
77</xsl:stylesheet>
78