Author: manuel Date: 2007-04-06 10:46:43 -0600 (Fri, 06 Apr 2007) New Revision: 8019
Modified: branches/new-xsl/pdf/lfs-xref.xsl Log: Revised pdf/lfs-xref.xsl Modified: branches/new-xsl/pdf/lfs-xref.xsl =================================================================== --- branches/new-xsl/pdf/lfs-xref.xsl 2007-04-06 16:10:40 UTC (rev 8018) +++ branches/new-xsl/pdf/lfs-xref.xsl 2007-04-06 16:46:43 UTC (rev 8019) @@ -1,80 +1,155 @@ <?xml version='1.0' encoding='ISO-8859-1'?> <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" + xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:fo="http://www.w3.org/1999/XSL/Format" + exclude-result-prefixes="xlink" version="1.0"> - <!-- Making a proper punctuation in xref (only for English language).--> + + <!-- This stylesheet fixes English punctuation in xref links + (as was requested by the publisher) via adding @role propagation + in xref tags. + This hack may not work with xref flavours not used in the book. + For other languages, just remove the xref @role attributes + in the book XML sources and/or comment-out the inclusion of + this file in lfs-pdf.xsl --> + + <!-- xref: + Added role variable and use it when calling mode xref-to.--> + <!-- The original template is in {docbook-xsl}/fo/xref.xsl --> <xsl:template match="xref" name="xref"> - <xsl:variable name="targets" select="key('id',@linkend)"/> - <xsl:variable name="target" select="$targets[1]"/> - <xsl:variable name="refelem" select="local-name($target)"/> + <xsl:param name="xhref" select="@xlink:href"/> + <!-- is the @xlink:href a local idref link? --> + <xsl:param name="xlink.idref"> + <xsl:if test="starts-with($xhref,'#') + and (not(contains($xhref,'(')) + or starts-with($xhref, '#xpointer(id('))"> + <xsl:call-template name="xpointer.idref"> + <xsl:with-param name="xpointer" select="$xhref"/> + </xsl:call-template> + </xsl:if> + </xsl:param> + <xsl:param name="xlink.targets" select="key('id',$xlink.idref)"/> + <xsl:param name="linkend.targets" select="key('id',@linkend)"/> + <xsl:param name="target" select="($xlink.targets | $linkend.targets)[1]"/> + <xsl:param name="refelem" select="local-name($target)"/> + <!-- Added role variable --> <xsl:variable name="role" select="@role"/> - <xsl:call-template name="check.id.unique"> - <xsl:with-param name="linkend" select="@linkend"/> + <xsl:variable name="xrefstyle"> + <xsl:choose> + <xsl:when test="@role and not(@xrefstyle) + and $use.role.as.xrefstyle != 0"> + <xsl:value-of select="@role"/> + </xsl:when> + <xsl:otherwise> + <xsl:value-of select="@xrefstyle"/> + </xsl:otherwise> + </xsl:choose> + </xsl:variable> + <xsl:variable name="content"> + <fo:inline xsl:use-attribute-sets="xref.properties"> + <xsl:choose> + <xsl:when test="@endterm"> + <xsl:variable name="etargets" select="key('id',@endterm)"/> + <xsl:variable name="etarget" select="$etargets[1]"/> + <xsl:choose> + <xsl:when test="count($etarget) = 0"> + <xsl:message> + <xsl:value-of select="count($etargets)"/> + <xsl:text>Endterm points to nonexistent ID: </xsl:text> + <xsl:value-of select="@endterm"/> + </xsl:message> + <xsl:text>???</xsl:text> + </xsl:when> + <xsl:otherwise> + <xsl:apply-templates select="$etarget" mode="endterm"/> + </xsl:otherwise> + </xsl:choose> + </xsl:when> + <xsl:when test="$target/@xreflabel"> + <xsl:call-template name="xref.xreflabel"> + <xsl:with-param name="target" select="$target"/> + </xsl:call-template> + </xsl:when> + <xsl:when test="$target"> + <xsl:if test="not(parent::citation)"> + <xsl:apply-templates select="$target" mode="xref-to-prefix"/> + </xsl:if> + <xsl:apply-templates select="$target" mode="xref-to"> + <xsl:with-param name="referrer" select="."/> + <xsl:with-param name="xrefstyle" select="$xrefstyle"/> + <!-- Propagate role --> + <xsl:with-param name="role" select="$role"/> + </xsl:apply-templates> + <xsl:if test="not(parent::citation)"> + <xsl:apply-templates select="$target" mode="xref-to-suffix"/> + </xsl:if> + </xsl:when> + <xsl:otherwise> + <xsl:message> + <xsl:text>ERROR: xref linking to </xsl:text> + <xsl:value-of select="@linkend|@xlink:href"/> + <xsl:text> has no generated link text.</xsl:text> + </xsl:message> + <xsl:text>???</xsl:text> + </xsl:otherwise> + </xsl:choose> + </fo:inline> + </xsl:variable> + <!-- Convert it into an active link --> + <xsl:call-template name="simple.xlink"> + <xsl:with-param name="content" select="$content"/> </xsl:call-template> + <!-- Add standard page reference? --> <xsl:choose> - <xsl:when test="$refelem=''"> - <xsl:message> - <xsl:text>XRef to nonexistent id: </xsl:text> - <xsl:value-of select="@linkend"/> - </xsl:message> - <xsl:text>???</xsl:text> + <xsl:when test="not($target)"> + <!-- page numbers only for local targets --> </xsl:when> - <xsl:when test="$target/@xreflabel"> - <fo:basic-link internal-destination="[EMAIL PROTECTED]" - xsl:use-attribute-sets="xref.properties"> - <xsl:call-template name="xref.xreflabel"> - <xsl:with-param name="target" select="$target"/> - </xsl:call-template> - </fo:basic-link> + <xsl:when test="starts-with(normalize-space($xrefstyle), 'select:') + and contains($xrefstyle, 'nopage')"> + <!-- negative xrefstyle in instance turns it off --> </xsl:when> - <xsl:otherwise> - <fo:basic-link internal-destination="[EMAIL PROTECTED]" - xsl:use-attribute-sets="xref.properties"> - <xsl:apply-templates select="$target" mode="xref-to"> - <xsl:with-param name="referrer" select="."/> - <xsl:with-param name="role" select="$role"/> - <xsl:with-param name="xrefstyle"> - <xsl:value-of select="@xrefstyle"/> - </xsl:with-param> - </xsl:apply-templates> - </fo:basic-link> - </xsl:otherwise> - </xsl:choose> - <!-- Add standard page reference? --> - <xsl:if test="not(starts-with(normalize-space(@xrefstyle), 'select:') != '' - and (contains(@xrefstyle, 'page') - or contains(@xrefstyle, 'Page'))) - and ( $insert.xref.page.number = 'yes' - or $insert.xref.page.number = '1') - or local-name($target) = 'para'"> - <fo:basic-link internal-destination="[EMAIL PROTECTED]" - xsl:use-attribute-sets="xref.properties"> + <!-- positive xrefstyle already handles it --> + <xsl:when test="not(starts-with(normalize-space($xrefstyle), 'select:') + and (contains($xrefstyle, 'page') + or contains($xrefstyle, 'Page'))) + and ( $insert.xref.page.number = 'yes' + or $insert.xref.page.number = '1') + or local-name($target) = 'para'"> <xsl:apply-templates select="$target" mode="page.citation"> - <xsl:with-param name="id" select="@linkend"/> + <xsl:with-param name="id" select="$target/@id|$target/@xml:id"/> </xsl:apply-templates> - </fo:basic-link> - </xsl:if> + </xsl:when> + </xsl:choose> </xsl:template> + <!-- sect* mode xref-to: + Propagate role to mode object.xref.markup --> + <!-- The original template is in {docbook-xsl}/fo/xref.xsl --> <xsl:template match="section|simplesect|sect1|sect2|sect3|sect4|sect5 |refsect1|refsect2|refsect3|refsection" mode="xref-to"> <xsl:param name="referrer"/> <xsl:param name="xrefstyle"/> + <xsl:param name="verbose" select="1"/> <xsl:param name="role"/> <xsl:apply-templates select="." mode="object.xref.markup"> <xsl:with-param name="purpose" select="'xref'"/> <xsl:with-param name="xrefstyle" select="$xrefstyle"/> <xsl:with-param name="referrer" select="$referrer"/> + <xsl:with-param name="verbose" select="$verbose"/> <xsl:with-param name="role" select="$role"/> </xsl:apply-templates> </xsl:template> + <!-- mode object.xref.markup: + Propagate role to named template substitute-markup --> + <!-- The original template is in {docbook-xsl}/common/gentext.xsl --> <xsl:template match="*" mode="object.xref.markup"> <xsl:param name="purpose"/> <xsl:param name="xrefstyle"/> <xsl:param name="referrer"/> + <xsl:param name="verbose" select="1"/> <xsl:param name="role"/> <xsl:variable name="template"> <xsl:choose> @@ -97,11 +172,11 @@ </xsl:otherwise> </xsl:choose> </xsl:variable> - <xsl:if test="$template = ''"> + <xsl:if test="$template = '' and $verbose != 0"> <xsl:message> <xsl:text>object.xref.markup: empty xref template</xsl:text> <xsl:text> for linkend="</xsl:text> - <xsl:value-of select="@id"/> + <xsl:value-of select="@id|@xml:id"/> <xsl:text>" and @xrefstyle="</xsl:text> <xsl:value-of select="$xrefstyle"/> <xsl:text>"</xsl:text> @@ -112,26 +187,32 @@ <xsl:with-param name="xrefstyle" select="$xrefstyle"/> <xsl:with-param name="referrer" select="$referrer"/> <xsl:with-param name="template" select="$template"/> + <xsl:with-param name="verbose" select="$verbose"/> <xsl:with-param name="role" select="$role"/> </xsl:call-template> </xsl:template> + <!-- substitute-markup: + Propagate role to mode insert.title.markup --> + <!-- The original template is in {docbook-xsl}/common/gentext.xsl --> <xsl:template name="substitute-markup"> <xsl:param name="template" select="''"/> <xsl:param name="allow-anchors" select="'0'"/> <xsl:param name="title" select="''"/> <xsl:param name="subtitle" select="''"/> + <xsl:param name="docname" select="''"/> <xsl:param name="label" select="''"/> <xsl:param name="pagenumber" select="''"/> <xsl:param name="purpose"/> <xsl:param name="xrefstyle"/> <xsl:param name="referrer"/> + <xsl:param name="verbose"/> <xsl:param name="role"/> <xsl:choose> <xsl:when test="contains($template, '%')"> <xsl:value-of select="substring-before($template, '%')"/> <xsl:variable name="candidate" - select="substring(substring-after($template, '%'), 1, 1)"/> + select="substring(substring-after($template, '%'), 1, 1)"/> <xsl:choose> <xsl:when test="$candidate = 't'"> <xsl:apply-templates select="." mode="insert.title.markup"> @@ -146,6 +227,7 @@ <xsl:otherwise> <xsl:apply-templates select="." mode="title.markup"> <xsl:with-param name="allow-anchors" select="$allow-anchors"/> + <xsl:with-param name="verbose" select="$verbose"/> </xsl:apply-templates> </xsl:otherwise> </xsl:choose> @@ -202,6 +284,23 @@ </xsl:with-param> </xsl:apply-templates> </xsl:when> + <xsl:when test="$candidate = 'o'"> + <!-- olink target document title --> + <xsl:apply-templates select="." mode="insert.olink.docname.markup"> + <xsl:with-param name="purpose" select="$purpose"/> + <xsl:with-param name="xrefstyle" select="$xrefstyle"/> + <xsl:with-param name="docname"> + <xsl:choose> + <xsl:when test="$docname != ''"> + <xsl:copy-of select="$docname"/> + </xsl:when> + <xsl:otherwise> + <xsl:apply-templates select="." mode="olink.docname.markup"/> + </xsl:otherwise> + </xsl:choose> + </xsl:with-param> + </xsl:apply-templates> + </xsl:when> <xsl:when test="$candidate = 'd'"> <xsl:apply-templates select="." mode="insert.direction.markup"> <xsl:with-param name="purpose" select="$purpose"/> @@ -250,11 +349,13 @@ <xsl:with-param name="allow-anchors" select="$allow-anchors"/> <xsl:with-param name="title" select="$title"/> <xsl:with-param name="subtitle" select="$subtitle"/> + <xsl:with-param name="docname" select="$docname"/> <xsl:with-param name="label" select="$label"/> <xsl:with-param name="pagenumber" select="$pagenumber"/> <xsl:with-param name="purpose" select="$purpose"/> <xsl:with-param name="xrefstyle" select="$xrefstyle"/> <xsl:with-param name="referrer" select="$referrer"/> + <xsl:with-param name="verbose" select="$verbose"/> <xsl:with-param name="role" select="$role"/> </xsl:call-template> </xsl:when> @@ -264,6 +365,9 @@ </xsl:choose> </xsl:template> + <!-- insert.title.markup: + Apply the role value. --> + <!-- The original template is in {docbook-xsl}/fo/xref.xsl --> <xsl:template match="*" mode="insert.title.markup"> <xsl:param name="purpose"/> <xsl:param name="xrefstyle"/> @@ -280,4 +384,4 @@ </xsl:choose> </xsl:template> -</xsl:stylesheet> \ No newline at end of file +</xsl:stylesheet> -- http://linuxfromscratch.org/mailman/listinfo/lfs-book FAQ: http://www.linuxfromscratch.org/lfs/faq.html Unsubscribe: See the above information page
