docbook-apps

  • 1.  Customizing processing instructions

    Posted 10-29-2012 11:35
    I'm trying to create a custom processing instruction to insert and
    format a background image in a chapter abstract. I've followed the
    instructions in Chapter 9 of DocBook XSL TDG but am getting error
    messages about empty parameters.

    The XML is:

    <abstract>




    <para>The text in ... </para>
    </abstract>
    </info>

    (I'd like to combine all three params into one pi if possible.)

    I've set up variables for background-image, content-width and position:

    <xsl:templatematch="d:abstract"mode="chapter.titlepage.recto.auto.mode">
    <xsl:variablename="bgimage">
    <xsl:call-templatename="dbfo-attribute">
    <xsl:with-paramname="pis"
    select="ancestor-or-self::d:abstract/processing-instruction('dbfo')"/>
    <xsl:with-paramname="attribute"select="'background-image'"/>
    </xsl:call-template>
    </xsl:variable>
    <xsl:variablename="bgwidth">
    <xsl:call-templatename="dbfo-attribute">
    <xsl:with-paramname="pis"
    select="ancestor-or-self::d:abstract/processing-instruction('dbfo')"/>
    <xsl:with-paramname="attribute"select="'ex:background-content-width'"/>
    </xsl:call-template>
    </xsl:variable>
    <xsl:variablename="bgposition">
    <xsl:call-templatename="dbfo-attribute">
    <xsl:with-paramname="pis"
    select="ancestor-or-self::d:abstract/processing-instruction('dbfo')"/>
    <xsl:with-paramname="attribute"select="'background-position'"/>
    </xsl:call-template>
    </xsl:variable>

    <fo:blockxmlns:fo="http://www.w3.org/1999/XSL/Format"
    xmlns:ex="http://www.renderx.com/XSL/Extensions"
    xsl:use-attribute-sets="chapsummaryprops"
    background-image="{$bgimage}"
    ex:background-content-width="{$bgwidth}"
    background-position="{$bgposition}">
    <xsl:apply-templatesselect="d:title"/>
    <xsl:apply-templatesselect="d:para"/>

    </fo:block>
    </xsl:template>

    And when I process it with Saxon 6.5.5 the error messages are:

    [warning] Attribute 'background-image' cannot have a value of "": should
    be either 'inherit' or a URI: background-image="url(...)".
    [error] Attribute 'rx:background-content-width' cannot have a value of "".

    I'm using DB 1.77.1, XEP 4.19.

    Thanks

    --
    *Dave Gardiner*




  • 2.  Renaming processing instructions

    Posted 10-30-2012 10:11
    I have managed to (mostly) achieve the PIs I need, but I'd like to know
    if it's possible to rename PIs to shorten the amount of text.
    In the XML I have:
    <abstract>
    ex:background-content-width="60mm"?>

    ...

    My customization so far needs to use those long names
    ("background-image", etc.). Can I somehow rename these to, say,
    "bgimage" instead of "background-image"?

    My customization is:
    <xsl:template match="d:abstract" mode="chapter.titlepage.recto.auto.mode">

    <xsl:variable name="bgroundimage">
    <xsl:call-template name="dbfo-attribute">
    <xsl:with-param name="pis"

    select="ancestor-or-self::d:abstract/processing-instruction('dbfo')"/>
    <xsl:with-param name="attribute" select="'background-image'"/>
    </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="backgroundimg">
    <xsl:value-of select="concat('url(', $bgroundimage, ')')"/>
    </xsl:variable>

    <xsl:variable name="bgroundwidth">
    <xsl:call-template name="dbfo-attribute">
    <xsl:with-param name="pis"

    select="ancestor-or-self::d:abstract/processing-instruction('dbfo')"/>
    <xsl:with-param name="attribute" select="'ex:background-content-width'"/>
    </xsl:call-template>
    </xsl:variable>

    <xsl:variable name="bgroundposition">
    <xsl:call-template name="dbfo-attribute">
    <xsl:with-param name="pis"

    select="ancestor-or-self::d:abstract/processing-instruction('dbfo')"/>
    <xsl:with-param name="attribute" select="'background-position'"/>
    </xsl:call-template>
    </xsl:variable>

    <fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format"
    xmlns:ex="http://www.renderx.com/XSL/Extensions"
    xsl:use-attribute-sets="chapsummaryprops">
    <xsl:if test="processing-instruction()">
    <xsl:attribute name="background-image">
    <xsl:value-of select="$backgroundimg"/>
    </xsl:attribute>
    <xsl:attribute name="ex:background-content-width">
    <xsl:value-of select="$bgroundwidth"/>
    </xsl:attribute>
    <xsl:attribute name="background-position">
    <xsl:value-of select="$bgroundposition"/>
    </xsl:attribute>
    </xsl:if>

    <xsl:apply-templates select="d:title" />
    <xsl:apply-templates select="d:para" />
    </fo:block>
    </xsl:template>

    Thanks,

    On 29-10-12 10:35 PM, Xmplar wrote:
    >
    > I'm trying to create a custom processing instruction to insert and
    > format a background image in a chapter abstract. I've followed the
    > instructions in Chapter 9 of DocBook XSL TDG but am getting error
    > messages about empty parameters.
    >
    > The XML is:
    >
    > <abstract>
    >
    >
    >
    >
    > <para>The text in ... </para>
    > </abstract>
    > </info>
    >
    > (I'd like to combine all three params into one pi if possible.)
    >
    > I've set up variables for background-image, content-width and position:
    >
    > <xsl:templatematch="d:abstract"mode="chapter.titlepage.recto.auto.mode">
    > <xsl:variablename="bgimage">
    > <xsl:call-templatename="dbfo-attribute">
    > <xsl:with-paramname="pis"
    > select="ancestor-or-self::d:abstract/processing-instruction('dbfo')"/>
    > <xsl:with-paramname="attribute"select="'background-image'"/>
    > </xsl:call-template>
    > </xsl:variable>
    > <xsl:variablename="bgwidth">
    > <xsl:call-templatename="dbfo-attribute">
    > <xsl:with-paramname="pis"
    > select="ancestor-or-self::d:abstract/processing-instruction('dbfo')"/>
    > <xsl:with-paramname="attribute"select="'ex:background-content-width'"/>
    > </xsl:call-template>
    > </xsl:variable>
    > <xsl:variablename="bgposition">
    > <xsl:call-templatename="dbfo-attribute">
    > <xsl:with-paramname="pis"
    > select="ancestor-or-self::d:abstract/processing-instruction('dbfo')"/>
    > <xsl:with-paramname="attribute"select="'background-position'"/>
    > </xsl:call-template>
    > </xsl:variable>
    >
    > <fo:blockxmlns:fo="http://www.w3.org/1999/XSL/Format"
    > xmlns:ex="http://www.renderx.com/XSL/Extensions"
    > xsl:use-attribute-sets="chapsummaryprops"
    > background-image="{$bgimage}"
    > ex:background-content-width="{$bgwidth}"
    > background-position="{$bgposition}">
    > <xsl:apply-templatesselect="d:title"/>
    > <xsl:apply-templatesselect="d:para"/>
    >
    > </fo:block>
    > </xsl:template>
    >
    > And when I process it with Saxon 6.5.5 the error messages are:
    >
    > [warning] Attribute 'background-image' cannot have a value of "":
    > should be either 'inherit' or a URI: background-image="url(...)".
    > [error] Attribute 'rx:background-content-width' cannot have a value of "".
    >
    > I'm using DB 1.77.1, XEP 4.19.
    >
    > Thanks
    >
    > --
    > *Dave Gardiner*
    >




  • 3.  Re: [docbook-apps] Renaming processing instructions

    Posted 10-30-2012 16:11
    Yes, you can use names in the PIs that differ from the output attribute
    names. In fact, there is no automatic passthrough. The information inside a
    dbfo PI is actually pseudo-attributes. They look like attributes, but they
    are just text strings organized in a way that can assign a value to a name.
    The PI processing templates parse them as strings to extract a value
    assigned to a given pseudo-attribute name. Then some template has to
    generate an actual <xsl:attribute> to assign the value to an output
    attribute name, which is independent of the pseudo-attribute name. So your
    example could be:

    A PI in the source file:



    Extracting the value:

    <xsl:variable name="bgroundimage">
    <xsl:call-template name="dbfo-attribute">
    <xsl:with-param name="pis"
    select="ancestor-or-self::d:abstract/processing-instruction('dbfo')"/>
    <xsl:with-param name="attribute" select="bgimage"/>
    </xsl:call-template>
    </xsl:variable>

    <xsl:variable name="backgroundimg">
    <xsl:value-of select="concat('url(', $bgroundimage, ')')"/>
    </xsl:variable>

    and further down, using the value for an output attribute:

    <xsl:attribute name="background-image">
    <xsl:value-of select="$backgroundimg"/>
    </xsl:attribute>


    Bob Stayton
    Sagehill Enterprises
    bobs@sagehill.net



    From: Xmplar
    Sent: Tuesday, October 30, 2012 3:11 AM
    To: docbook-apps@lists.oasis-open.org
    Subject: [docbook-apps] Renaming processing instructions


    I have managed to (mostly) achieve the PIs I need, but I'd like to know if
    it's possible to rename PIs to shorten the amount of text.
    In the XML I have:
    <abstract>
    background-position="0% 30%" ex:background-content-width="60mm"?>

    ...

    My customization so far needs to use those long names ("background-image",
    etc.). Can I somehow rename these to, say, "bgimage" instead of
    "background-image"?

    My customization is:
    <xsl:template match="d:abstract" mode="chapter.titlepage.recto.auto.mode">

    <xsl:variable name="bgroundimage">
    <xsl:call-template name="dbfo-attribute">
    <xsl:with-param name="pis"
    select="ancestor-or-self::d:abstract/processing-instruction('dbfo')"/>
    <xsl:with-param name="attribute" select="'background-image'"/>
    </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="backgroundimg">
    <xsl:value-of select="concat('url(', $bgroundimage, ')')"/>
    </xsl:variable>

    <xsl:variable name="bgroundwidth">
    <xsl:call-template name="dbfo-attribute">
    <xsl:with-param name="pis"
    select="ancestor-or-self::d:abstract/processing-instruction('dbfo')"/>
    <xsl:with-param name="attribute"
    select="'ex:background-content-width'"/>
    </xsl:call-template>
    </xsl:variable>

    <xsl:variable name="bgroundposition">
    <xsl:call-template name="dbfo-attribute">
    <xsl:with-param name="pis"
    select="ancestor-or-self::d:abstract/processing-instruction('dbfo')"/>
    <xsl:with-param name="attribute" select="'background-position'"/>
    </xsl:call-template>
    </xsl:variable>

    <fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format"
    xmlns:ex="http://www.renderx.com/XSL/Extensions"
    xsl:use-attribute-sets="chapsummaryprops">
    <xsl:if test="processing-instruction()">
    <xsl:attribute name="background-image">
    <xsl:value-of select="$backgroundimg"/>
    </xsl:attribute>
    <xsl:attribute name="ex:background-content-width">
    <xsl:value-of select="$bgroundwidth"/>
    </xsl:attribute>
    <xsl:attribute name="background-position">
    <xsl:value-of select="$bgroundposition"/>
    </xsl:attribute>
    </xsl:if>

    <xsl:apply-templates select="d:title" />
    <xsl:apply-templates select="d:para" />
    </fo:block>
    </xsl:template>

    Thanks,

    On 29-10-12 10:35 PM, Xmplar wrote:
    I'm trying to create a custom processing instruction to insert and format a
    background image in a chapter abstract. I've followed the instructions in
    Chapter 9 of DocBook XSL TDG but am getting error messages about empty
    parameters.
    The XML is:
    <abstract>




    <para>The text in . </para>
    </abstract>
    </info>
    (I'd like to combine all three params into one pi if possible.)

    I've set up variables for background-image, content-width and position:
    <xsl:template match="d:abstract" mode="chapter.titlepage.recto.auto.mode">
    <xsl:variable name="bgimage">
    <xsl:call-template name="dbfo-attribute">
    <xsl:with-param name="pis"
    select="ancestor-or-self::d:abstract/processing-instruction('dbfo')"/>
    <xsl:with-param name="attribute" select="'background-image'"/>
    </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="bgwidth">
    <xsl:call-template name="dbfo-attribute">
    <xsl:with-param name="pis"
    select="ancestor-or-self::d:abstract/processing-instruction('dbfo')"/>
    <xsl:with-param name="attribute"
    select="'ex:background-content-width'"/>
    </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="bgposition">
    <xsl:call-template name="dbfo-attribute">
    <xsl:with-param name="pis"
    select="ancestor-or-self::d:abstract/processing-instruction('dbfo')"/>
    <xsl:with-param name="attribute" select="'background-position'"/>
    </xsl:call-template>
    </xsl:variable>

    <fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format"
    xmlns:ex="http://www.renderx.com/XSL/Extensions"
    xsl:use-attribute-sets="chapsummaryprops"
    background-image="{$bgimage}"
    ex:background-content-width="{$bgwidth}"
    background-position="{$bgposition}">
    <xsl:apply-templates select="d:title" />
    <xsl:apply-templates select="d:para" />

    </fo:block>
    </xsl:template>

    And when I process it with Saxon 6.5.5 the error messages are:
    [warning] Attribute 'background-image' cannot have a value of "": should be
    either 'inherit' or a URI: background-image="url(...)".
    [error] Attribute 'rx:background-content-width' cannot have a value of
    "".
    I'm using DB 1.77.1, XEP 4.19.
    Thanks
    --
    Dave Gardiner




  • 4.  Re: [docbook-apps] Renaming processing instructions

    Posted 10-31-2012 09:32
    Thanks Bob - works perfectly.
    I had to declare my custom PI names as strings when calling the
    dbfo-attribute template, so there are extra quote marks around each name
    in the following line:
    <xsl:with-param name="attribute" select="*'*bgposition*'*"/>

    Dave

    On 31-10-12 3:10 AM, Bob Stayton wrote:
    > Yes, you can use names in the PIs that differ from the output
    > attribute names. In fact, there is no automatic passthrough. The
    > information inside a dbfo PI is actually pseudo-attributes. They look
    > like attributes, but they are just text strings organized in a way
    > that can assign a value to a name. The PI processing templates parse
    > them as strings to extract a value assigned to a given
    > pseudo-attribute name. Then some template has to generate an actual
    > <xsl:attribute> to assign the value to an output attribute name, which
    > is independent of the pseudo-attribute name. So your example could be:
    >
    > A PI in the source file:
    >
    >
    >
    > Extracting the value:
    >
    > <xsl:variable name="bgroundimage">
    > <xsl:call-template name="dbfo-attribute">
    > <xsl:with-param name="pis"
    >
    > select="ancestor-or-self::d:abstract/processing-instruction('dbfo')"/>
    > <xsl:with-param name="attribute" select="bgimage"/>
    > </xsl:call-template>
    > </xsl:variable>
    >
    > <xsl:variable name="backgroundimg">
    > <xsl:value-of select="concat('url(', $bgroundimage, ')')"/>
    > </xsl:variable>
    >
    > and further down, using the value for an output attribute:
    >
    > <xsl:attribute name="background-image">
    > <xsl:value-of select="$backgroundimg"/>
    > </xsl:attribute>
    >
    >
    > Bob Stayton
    > Sagehill Enterprises
    > bobs@sagehill.net
    >
    >
    >
    > From: Xmplar
    > Sent: Tuesday, October 30, 2012 3:11 AM
    > To: docbook-apps@lists.oasis-open.org
    > Subject: [docbook-apps] Renaming processing instructions
    >
    >
    > I have managed to (mostly) achieve the PIs I need, but I'd like to
    > know if it's possible to rename PIs to shorten the amount of text.
    > In the XML I have:
    > <abstract>
    > > 30%" ex:background-content-width="60mm"?>
    >
    > ...
    >
    > My customization so far needs to use those long names
    > ("background-image", etc.). Can I somehow rename these to, say,
    > "bgimage" instead of "background-image"?
    >
    > My customization is:
    > <xsl:template match="d:abstract"
    > mode="chapter.titlepage.recto.auto.mode">
    >
    > <xsl:variable name="bgroundimage">
    > <xsl:call-template name="dbfo-attribute">
    > <xsl:with-param name="pis"
    >
    > select="ancestor-or-self::d:abstract/processing-instruction('dbfo')"/>
    > <xsl:with-param name="attribute" select="'background-image'"/>
    > </xsl:call-template>
    > </xsl:variable>
    > <xsl:variable name="backgroundimg">
    > <xsl:value-of select="concat('url(', $bgroundimage, ')')"/>
    > </xsl:variable>
    >
    > <xsl:variable name="bgroundwidth">
    > <xsl:call-template name="dbfo-attribute">
    > <xsl:with-param name="pis"
    >
    > select="ancestor-or-self::d:abstract/processing-instruction('dbfo')"/>
    > <xsl:with-param name="attribute" select="'ex:background-content-width'"/>
    > </xsl:call-template>
    > </xsl:variable>
    >
    > <xsl:variable name="bgroundposition">
    > <xsl:call-template name="dbfo-attribute">
    > <xsl:with-param name="pis"
    >
    > select="ancestor-or-self::d:abstract/processing-instruction('dbfo')"/>
    > <xsl:with-param name="attribute" select="'background-position'"/>
    > </xsl:call-template>
    > </xsl:variable>
    >
    > <fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format"
    > xmlns:ex="http://www.renderx.com/XSL/Extensions"
    > xsl:use-attribute-sets="chapsummaryprops">
    > <xsl:if test="processing-instruction()">
    > <xsl:attribute name="background-image">
    > <xsl:value-of select="$backgroundimg"/>
    > </xsl:attribute>
    > <xsl:attribute name="ex:background-content-width">
    > <xsl:value-of select="$bgroundwidth"/>
    > </xsl:attribute>
    > <xsl:attribute name="background-position">
    > <xsl:value-of select="$bgroundposition"/>
    > </xsl:attribute>
    > </xsl:if>
    >
    > <xsl:apply-templates select="d:title" />
    > <xsl:apply-templates select="d:para" />
    > </fo:block>
    > </xsl:template>
    >
    > Thanks,
    >
    > On 29-10-12 10:35 PM, Xmplar wrote:
    > I'm trying to create a custom processing instruction to insert and
    > format a background image in a chapter abstract. I've followed the
    > instructions in Chapter 9 of DocBook XSL TDG but am getting error
    > messages about empty parameters.
    > The XML is:
    > <abstract>
    >
    >
    >
    >
    > <para>The text in . </para>
    > </abstract>
    > </info>
    > (I'd like to combine all three params into one pi if possible.)
    >
    > I've set up variables for background-image, content-width and position:
    > <xsl:template match="d:abstract"
    > mode="chapter.titlepage.recto.auto.mode">
    > <xsl:variable name="bgimage">
    > <xsl:call-template name="dbfo-attribute">
    > <xsl:with-param name="pis"
    >
    > select="ancestor-or-self::d:abstract/processing-instruction('dbfo')"/>
    > <xsl:with-param name="attribute" select="'background-image'"/>
    > </xsl:call-template>
    > </xsl:variable>
    > <xsl:variable name="bgwidth">
    > <xsl:call-template name="dbfo-attribute">
    > <xsl:with-param name="pis"
    >
    > select="ancestor-or-self::d:abstract/processing-instruction('dbfo')"/>
    > <xsl:with-param name="attribute" select="'ex:background-content-width'"/>
    > </xsl:call-template>
    > </xsl:variable>
    > <xsl:variable name="bgposition">
    > <xsl:call-template name="dbfo-attribute">
    > <xsl:with-param name="pis"
    >
    > select="ancestor-or-self::d:abstract/processing-instruction('dbfo')"/>
    > <xsl:with-param name="attribute" select="'background-position'"/>
    > </xsl:call-template>
    > </xsl:variable>
    >
    > <fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format"
    > xmlns:ex="http://www.renderx.com/XSL/Extensions"
    > xsl:use-attribute-sets="chapsummaryprops"
    > background-image="{$bgimage}"
    > ex:background-content-width="{$bgwidth}"
    > background-position="{$bgposition}">
    > <xsl:apply-templates select="d:title" />
    > <xsl:apply-templates select="d:para" />
    >
    > </fo:block>
    > </xsl:template>
    >
    > And when I process it with Saxon 6.5.5 the error messages are:
    > [warning] Attribute 'background-image' cannot have a value of "":
    > should be either 'inherit' or a URI: background-image="url(...)".
    > [error] Attribute 'rx:background-content-width' cannot have a value
    > of "".
    > I'm using DB 1.77.1, XEP 4.19.
    > Thanks