docbook-apps

  • 1.  xrefs to

    Posted 04-05-2013 01:01
    My company has a hundred or so books that were authored with Arbortext's graphic XML editor. I'm having a problem processing these books with XSL-FO because so many of the xrefs in these books are to title elements instead of the parent procedure, section, example, table, etc., elements.

    Is there a way to make these work in the XSL-FO output? I was thinking I could have a template that could recognize when an xref/@linkend pointed to the id of a title and then change the linkend to the id of the title's parent element, but I don't really know how to do that.

    Is there another way to do what I need to do?

    Eric Nordlund
    Customer Documentation and Training
    Cray Inc.
    901 5th Ave
    Seattle, WA 98164
    (206)701-2232




  • 2.  Re: [docbook-apps] xrefs to

    Posted 04-05-2013 06:54
    Hi Eric,

    On Fri, 5 Apr 2013 01:00:45 +0000
    Eric Nordlund <nordlund@cray.com> wrote:

    > [... @id attributes in titles instead of parent...]
    >
    > Is there a way to make these work in the XSL-FO output? I was
    > thinking I could have a template that could recognize when an
    > xref/@linkend pointed to the id of a title and then change the
    > linkend to the id of the title's parent element, but I don't really
    > know how to do that.
    >
    > Is there another way to do what I need to do?

    Well, my impression was that the DocBook XSL stylesheets takes this
    into account, so in theory it doesn't matter if the @id was placed
    wrongly. Maybe I'm wrong, I haven't tested that.

    However, if you really care, I would target your issue from a different
    angle: use XSLT to move your @id attribute to its parent element. Pass
    the result to your DocBook stylesheets (or your customization layer).
    No FO customization is needed in this case. :)

    Here is a stylesheet that moves an @id attribute from a title
    element to its parent element (probably it's incomplete, but it should
    be easy to extent it):

    ---------------------------------
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    version="1.0">

    <xsl:output method="xml"
    indent="yes"
    doctype-public="-//OASIS//DTD DocBook XML V4.5//EN"
    doctype-system="http://www.docbook.org/xml/4.5/docbookx.dtd"/>

    <xsl:template match="node() | @*" name="copy">
    <xsl:copy>
    <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
    </xsl:template>

    <xsl:template match="title/@id"/>

    <xsl:template name="copytitleid">
    <xsl:copy>
    <xsl:copy-of select="@*"/>
    <xsl:if test="(title/@id|
    *[contains(local-name(),'info')]/title/@id)">
    <xsl:attribute name="id">
    <xsl:value-of select="(title/@id|
    *[contains(local-name(),'info')]/title/@id)[1]"/>
    </xsl:attribute>
    </xsl:if>
    <xsl:apply-templates/>
    </xsl:copy>
    </xsl:template>

    <xsl:template match="appendix|article|book|
    bibliography|bibliodiv|
    chapter|colophon|
    dedication|glossary|
    preface|part|reference|
    refsection|refsect1|refsect2|refsect3|
    set|
    section|sect1|sect2|sect3|sect4|sect5">
    <xsl:call-template name="copytitleid"/>
    </xsl:template>

    <xsl:template match="figure|example|procedure|task">
    <xsl:call-template name="copytitleid"/>
    </xsl:template>

    </xsl:stylesheet>
    ---------------------------------

    --
    Gruß/Regards,
    Thomas Schraitle



  • 3.  Re: [docbook-apps] xrefs to

    Posted 04-05-2013 12:58
    It sounded like, from Nordlund's description, his sections already have
    IDs. So it might cause problems to replace those IDs.

    We'd need to know: do ALL xrefs target titles, NONE of them target actual
    sections?

    --Aaron DaMommio


    On Fri, Apr 5, 2013 at 1:53 AM, Thomas Schraitle <tom_schr@web.de> wrote:

    > Hi Eric,
    >
    > On Fri, 5 Apr 2013 01:00:45 +0000
    > Eric Nordlund <nordlund@cray.com> wrote:
    >
    > > [... @id attributes in titles instead of parent...]
    > >
    > > Is there a way to make these work in the XSL-FO output? I was
    > > thinking I could have a template that could recognize when an
    > > xref/@linkend pointed to the id of a title and then change the
    > > linkend to the id of the title's parent element, but I don't really
    > > know how to do that.
    > >
    > > Is there another way to do what I need to do?
    >
    > Well, my impression was that the DocBook XSL stylesheets takes this
    > into account, so in theory it doesn't matter if the @id was placed
    > wrongly. Maybe I'm wrong, I haven't tested that.
    >
    > However, if you really care, I would target your issue from a different
    > angle: use XSLT to move your @id attribute to its parent element. Pass
    > the result to your DocBook stylesheets (or your customization layer).
    > No FO customization is needed in this case. :)
    >
    > Here is a stylesheet that moves an @id attribute from a title
    > element to its parent element (probably it's incomplete, but it should
    > be easy to extent it):
    >
    > ---------------------------------
    > <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
    > version="1.0">
    >
    > <xsl:output method="xml"
    > indent="yes"
    > doctype-public="-//OASIS//DTD DocBook XML V4.5//EN"
    > doctype-system="http://www.docbook.org/xml/4.5/docbookx.dtd"/>
    >
    > <xsl:template match="node() | @*" name="copy">
    > <xsl:copy>
    > <xsl:apply-templates select="@* | node()"/>
    > </xsl:copy>
    > </xsl:template>
    >
    > <xsl:template match="title/@id"/>
    >
    > <xsl:template name="copytitleid">
    > <xsl:copy>
    > <xsl:copy-of select="@*"/>
    > <xsl:if test="(title/@id|
    > *[contains(local-name(),'info')]/title/@id)">
    > <xsl:attribute name="id">
    > <xsl:value-of select="(title/@id|
    >
    > *[contains(local-name(),'info')]/title/@id)[1]"/>
    > </xsl:attribute>
    > </xsl:if>
    > <xsl:apply-templates/>
    > </xsl:copy>
    > </xsl:template>
    >
    > <xsl:template match="appendix|article|book|
    > bibliography|bibliodiv|
    > chapter|colophon|
    > dedication|glossary|
    > preface|part|reference|
    > refsection|refsect1|refsect2|refsect3|
    > set|
    > section|sect1|sect2|sect3|sect4|sect5">
    > <xsl:call-template name="copytitleid"/>
    > </xsl:template>
    >
    > <xsl:template match="figure|example|procedure|task">
    > <xsl:call-template name="copytitleid"/>
    > </xsl:template>
    >
    > </xsl:stylesheet>
    > ---------------------------------
    >
    > --
    > Gruß/Regards,
    > Thomas Schraitle
    >
    > ---------------------------------------------------------------------
    > To unsubscribe, e-mail: docbook-apps-unsubscribe@lists.oasis-open.org
    > For additional commands, e-mail: docbook-apps-help@lists.oasis-open.org
    >
    >


    --
    --------------------------------------
    Aaron DaMommio: Husband, father, writer, juggler, and expert washer of
    dishes.
    - My blog: http://aarondamommio.blogspot.com
    - Need a juggler? http://amazingaaronjuggler.blogspot.com/
    =======================================



  • 4.  Re: [docbook-apps] xrefs to

    Posted 04-05-2013 16:18
    Hi Eric,
    Actually, creating an xref to a title used to work in the stylesheets. Currently it gets the generated text right, but the link is to the id of the title element, and most title elements do not output an @id attribute, so the link fails. It seems this feature was broken some time ago when the xref templates were rewritten to support universal linking in DocBook 5.

    This customization of the template named 'simple.xlink' from fo/inline.xsl fixes the id problem. It only corrects the problem for @linkend references, not for @xlink:href references used in universal linking, but it should suffice for your needs. Search for 'linkend.candidate' to see where I made the changes.


    <xsl:template name="simple.xlink">
    <xsl:param name="node" select="."/>
    <xsl:param name="content">
    <xsl:apply-templates/>
    </xsl:param>
    <xsl:param name="linkend.candidate" select="$node/@linkend"/>
    <xsl:param name="xhref" select="$node/@xlink:href"/>

    <xsl:choose>
    <xsl:when test="$xhref
    and (not($node/@xlink:type) or
    $node/@xlink:type='simple')">


    <xsl:variable name="is.idref">
    <xsl:choose>


    <xsl:when test="starts-with($xhref,'#')
    and (not(contains($xhref,'('))
    or starts-with($xhref,
    '#xpointer(id('))">1</xsl:when>
    <xsl:otherwise>0</xsl:otherwise>
    </xsl:choose>
    </xsl:variable>


    <xsl:variable name="is.olink">
    <xsl:choose>


    <xsl:when test="contains($xhref,'#') and
    @xlink:role = $xolink.role">1</xsl:when>
    <xsl:otherwise>0</xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    <xsl:choose>
    <xsl:when test="$is.olink = 1">
    <xsl:call-template name="olink">
    <xsl:with-param name="content" select="$content"/>
    </xsl:call-template>
    </xsl:when>

    <xsl:when test="$is.idref = 1">

    <xsl:variable name="idref">
    <xsl:call-template name="xpointer.idref">
    <xsl:with-param name="xpointer" select="$xhref"/>
    </xsl:call-template>
    </xsl:variable>

    <xsl:variable name="targets" select="key('id',$idref)"/>
    <xsl:variable name="target" select="$targets[1]"/>

    <xsl:call-template name="check.id.unique">
    <xsl:with-param name="linkend" select="$idref"/>
    </xsl:call-template>

    <xsl:choose>
    <xsl:when test="count($target) = 0">
    <xsl:message>
    <xsl:text>XLink to nonexistent id: </xsl:text>
    <xsl:value-of select="$idref"/>
    </xsl:message>
    <xsl:copy-of select="$content"/>
    </xsl:when>

    <xsl:otherwise>
    <fo:basic-link internal-destination="{$idref}">
    <xsl:apply-templates select="." mode="simple.xlink.properties"/>
    <xsl:copy-of select="$content"/>
    </fo:basic-link>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:when>


    <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>



    <xsl:call-template name="hyperlink.url.display">
    <xsl:with-param name="url" select="$xhref"/>
    </xsl:call-template>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:when>

    <xsl:when test="$linkend.candidate">
    <xsl:variable name="targets.candidate" select="key('id',$linkend.candidate)"/>
    <xsl:variable name="target.candidate" select="$targets.candidate[1]"/>

    <xsl:variable name="target.id">
    <xsl:choose>
    <xsl:when test="$target.candidate/self::title and
    $target.candidate/parent::*/@id">
    <xsl:value-of select="$target.candidate/parent::*/@id"/>
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="$target.candidate/@id"/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:variable>

    <xsl:variable name="targets" select="key('id',$target.id)"/>
    <xsl:variable name="target" select="$targets[1]"/>
    <xsl:variable name="linkend" select="$target/@id"/>

    <xsl:call-template name="check.id.unique">
    <xsl:with-param name="linkend" select="$linkend"/>
    </xsl:call-template>

    <xsl:choose>
    <xsl:when test="count($target) = 0">
    <xsl:message>
    <xsl:text>XLink to nonexistent id: </xsl:text>
    <xsl:value-of select="$linkend"/>
    </xsl:message>
    <xsl:copy-of select="$content"/>
    </xsl:when>

    <xsl:otherwise>
    <fo:basic-link internal-destination="{$linkend}">
    <xsl:apply-templates select="." mode="simple.xlink.properties"/>
    <xsl:copy-of select="$content"/>
    </fo:basic-link>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:when>

    <xsl:otherwise>
    <xsl:copy-of select="$content"/>
    </xsl:otherwise>
    </xsl:choose>
    </xsl:template>

    </xsl:stylesheet>

    Bob Stayton
    Sagehill Enterprises
    bobs@sagehill.net


    From: Eric Nordlund
    Sent: Thursday, April 04, 2013 6:00 PM
    To: docbook-apps@lists.oasis-open.org
    Subject: [docbook-apps] xrefs to


  • 5.  RE: [docbook-apps] xrefs to

    Posted 04-05-2013 18:11
    Thanks Bob. Your suggested style sheet customization worked for our documents; the links work and the correct text is displayed for the xref.

    One thing that I noticed is that the page.citation dows not work for the titles, however. This isn't a big deal for me because I just turn them off on title xrefs, but is there a way to get that template to work with title xrefs the same way that they would for section xrefs? Right now they show up as "


  • 6.  Re: [docbook-apps] xrefs to

    Posted 04-09-2013 17:12
    Hi Eric,
    The page numbers are not handled by the simple.xlink template, but by the template in fo/xref.xsl that matches on xref.

    <xsl:apply-templates select="$target" mode="page.citation">

    It is trying to process the title element (the value of $target) in mode="page.citation". It generates the correct code, but the id for title is not in the fo output, so the xsl-fo processor cannot find the id to get the page number. So you will need to create a template like this (untested) to generate the page citation for the parent of title:

    <xsl:template match="title" mode="page.citation">
    <xsl:apply-templates select="parent::*" mode="page.citation"/>
    </xsl:template>

    I think that will work.

    Bob Stayton
    Sagehill Enterprises
    bobs@sagehill.net


    From: Eric Nordlund
    Sent: Friday, April 05, 2013 11:11 AM
    To: Bob Stayton ; docbook-apps@lists.oasis-open.org
    Subject: RE: [docbook-apps] xrefs to


  • 7.  Re: [docbook-apps] xrefs to

    Posted 04-09-2013 17:57
    Actually, that template I wrote does not account for a title inside an info element, so that would require a xsl:choose I think.

    Bob Stayton
    Sagehill Enterprises
    bobs@sagehill.net


    From: Bob Stayton
    Sent: Tuesday, April 09, 2013 10:11 AM
    To: Eric Nordlund ; docbook-apps@lists.oasis-open.org
    Subject: Re: [docbook-apps] xrefs to