source: BOOK/stylesheets/lfs-xsl/pdf/lfs-xref.xsl@ 8a51bde

Last change on this file since 8a51bde was f8c4e94, checked in by Manuel Canales Esparcia <manuel@…>, 17 years ago

Added LFS XSL Stylesheets.

  • Property mode set to 100644
File size: 6.8 KB
Line 
1<?xml version='1.0' encoding='ISO-8859-1'?>
2
3<!--
4$LastChangedBy$
5$Date$
6-->
7
8<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
9 xmlns:xlink="http://www.w3.org/1999/xlink"
10 xmlns:fo="http://www.w3.org/1999/XSL/Format"
11 exclude-result-prefixes="xlink"
12 version="1.0">
13
14
15 <!-- This stylesheet fixes English punctuation in xref links
16 (as was requested by the publisher) via adding @role propagation
17 in xref tags.
18 This hack may not work with xref flavours not used in the book.
19 For other languages, just remove the xref @role attributes
20 in the book XML sources and/or comment-out the inclusion of
21 this file in lfs-pdf.xsl -->
22
23 <!-- xref:
24 Added role variable and use it when calling mode xref-to.-->
25 <!-- The original template is in {docbook-xsl}/fo/xref.xsl -->
26 <xsl:template match="xref" name="xref">
27 <xsl:param name="xhref" select="@xlink:href"/>
28 <!-- is the @xlink:href a local idref link? -->
29 <xsl:param name="xlink.idref">
30 <xsl:if test="starts-with($xhref,'#')
31 and (not(contains($xhref,'&#40;'))
32 or starts-with($xhref, '#xpointer&#40;id&#40;'))">
33 <xsl:call-template name="xpointer.idref">
34 <xsl:with-param name="xpointer" select="$xhref"/>
35 </xsl:call-template>
36 </xsl:if>
37 </xsl:param>
38 <xsl:param name="xlink.targets" select="key('id',$xlink.idref)"/>
39 <xsl:param name="linkend.targets" select="key('id',@linkend)"/>
40 <xsl:param name="target" select="($xlink.targets | $linkend.targets)[1]"/>
41 <xsl:param name="refelem" select="local-name($target)"/>
42 <!-- Added role variable -->
43 <xsl:variable name="role" select="@role"/>
44 <xsl:variable name="xrefstyle">
45 <xsl:choose>
46 <xsl:when test="@role and not(@xrefstyle)
47 and $use.role.as.xrefstyle != 0">
48 <xsl:value-of select="@role"/>
49 </xsl:when>
50 <xsl:otherwise>
51 <xsl:value-of select="@xrefstyle"/>
52 </xsl:otherwise>
53 </xsl:choose>
54 </xsl:variable>
55 <xsl:variable name="content">
56 <fo:inline xsl:use-attribute-sets="xref.properties">
57 <xsl:choose>
58 <xsl:when test="@endterm">
59 <xsl:variable name="etargets" select="key('id',@endterm)"/>
60 <xsl:variable name="etarget" select="$etargets[1]"/>
61 <xsl:choose>
62 <xsl:when test="count($etarget) = 0">
63 <xsl:message>
64 <xsl:value-of select="count($etargets)"/>
65 <xsl:text>Endterm points to nonexistent ID: </xsl:text>
66 <xsl:value-of select="@endterm"/>
67 </xsl:message>
68 <xsl:text>???</xsl:text>
69 </xsl:when>
70 <xsl:otherwise>
71 <xsl:apply-templates select="$etarget" mode="endterm"/>
72 </xsl:otherwise>
73 </xsl:choose>
74 </xsl:when>
75 <xsl:when test="$target/@xreflabel">
76 <xsl:call-template name="xref.xreflabel">
77 <xsl:with-param name="target" select="$target"/>
78 </xsl:call-template>
79 </xsl:when>
80 <xsl:when test="$target">
81 <xsl:if test="not(parent::citation)">
82 <xsl:apply-templates select="$target" mode="xref-to-prefix"/>
83 </xsl:if>
84 <xsl:apply-templates select="$target" mode="xref-to">
85 <xsl:with-param name="referrer" select="."/>
86 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
87 <!-- Propagate role -->
88 <xsl:with-param name="role" select="$role"/>
89 </xsl:apply-templates>
90 <xsl:if test="not(parent::citation)">
91 <xsl:apply-templates select="$target" mode="xref-to-suffix"/>
92 </xsl:if>
93 </xsl:when>
94 <xsl:otherwise>
95 <xsl:message>
96 <xsl:text>ERROR: xref linking to </xsl:text>
97 <xsl:value-of select="@linkend|@xlink:href"/>
98 <xsl:text> has no generated link text.</xsl:text>
99 </xsl:message>
100 <xsl:text>???</xsl:text>
101 </xsl:otherwise>
102 </xsl:choose>
103 </fo:inline>
104 </xsl:variable>
105 <!-- Convert it into an active link -->
106 <xsl:call-template name="simple.xlink">
107 <xsl:with-param name="content" select="$content"/>
108 </xsl:call-template>
109 <!-- Add standard page reference? -->
110 <xsl:choose>
111 <xsl:when test="not($target)">
112 <!-- page numbers only for local targets -->
113 </xsl:when>
114 <xsl:when test="starts-with(normalize-space($xrefstyle), 'select:')
115 and contains($xrefstyle, 'nopage')">
116 <!-- negative xrefstyle in instance turns it off -->
117 </xsl:when>
118 <!-- positive xrefstyle already handles it -->
119 <xsl:when test="not(starts-with(normalize-space($xrefstyle), 'select:')
120 and (contains($xrefstyle, 'page')
121 or contains($xrefstyle, 'Page')))
122 and ( $insert.xref.page.number = 'yes'
123 or $insert.xref.page.number = '1')
124 or local-name($target) = 'para'">
125 <xsl:apply-templates select="$target" mode="page.citation">
126 <xsl:with-param name="id" select="$target/@id|$target/@xml:id"/>
127 </xsl:apply-templates>
128 </xsl:when>
129 </xsl:choose>
130 </xsl:template>
131
132 <!-- sect* mode xref-to:
133 Propagate role to mode object.xref.markup (see ../lfs-common.xsl) -->
134 <!-- The original template is in {docbook-xsl}/fo/xref.xsl -->
135 <xsl:template match="section|simplesect|sect1|sect2|sect3|sect4|sect5
136 |refsect1|refsect2|refsect3|refsection" mode="xref-to">
137 <xsl:param name="referrer"/>
138 <xsl:param name="xrefstyle"/>
139 <xsl:param name="verbose" select="1"/>
140 <xsl:param name="role"/>
141 <xsl:apply-templates select="." mode="object.xref.markup">
142 <xsl:with-param name="purpose" select="'xref'"/>
143 <xsl:with-param name="xrefstyle" select="$xrefstyle"/>
144 <xsl:with-param name="referrer" select="$referrer"/>
145 <xsl:with-param name="verbose" select="$verbose"/>
146 <xsl:with-param name="role" select="$role"/>
147 </xsl:apply-templates>
148 </xsl:template>
149
150 <!-- insert.title.markup:
151 Apply the role value. -->
152 <!-- The original template is in {docbook-xsl}/fo/xref.xsl -->
153 <xsl:template match="*" mode="insert.title.markup">
154 <xsl:param name="purpose"/>
155 <xsl:param name="xrefstyle"/>
156 <xsl:param name="title"/>
157 <xsl:param name="role"/>
158 <xsl:choose>
159 <xsl:when test="$purpose = 'xref' and titleabbrev">
160 <xsl:apply-templates select="." mode="titleabbrev.markup"/>
161 </xsl:when>
162 <xsl:otherwise>
163 <xsl:copy-of select="$title"/>
164 <xsl:value-of select="$role"/>
165 </xsl:otherwise>
166 </xsl:choose>
167 </xsl:template>
168
169</xsl:stylesheet>
Note: See TracBrowser for help on using the repository browser.