docbook-apps

  • 1.  RE: [docbook-apps] user-defined text/background color in HTML output

    Posted 08-15-2016 14:41
    Hi Ekaterina,

    as far as I understood your original mail, you managed to get your
    list of values parsed in the case of XSL-FO.

    If not, you will have to write some XSLT to parse your pseudo-CSS...

    Expect this to be a bit hard -- XSLT (at least, 1.0) is not really
    made for string manipulation, and adding some error tolerance
    may bloat your code even more.

    Presumably, that parser would be based on first looking for a ";" ,
    splitting that string off, then looking where the ":" within your
    split-off string is. And then you would continue...

    If you are looking for inspiration, in your local DocBook stylesheets
    installation, take a look at lib/lib.xsl, and specifically the
    template "pi-attribute". This template solves a similar issue, trying
    to figure out constructs like 'attribute="value"'.

    You can also take a look at my horrible old code to parse things
    like 'attribute = value;' [1].

    You would then have to add in a list of attributes to allow and a list
    of color names to allow. And then match against those.

    Hth,

    Stefan.


    [1]
    https://github.com/openSUSE/suse-xsl/blob/88451ccc3006b20900e0b28371ba8805362ed819/suse2013/fo/l10n.properties.xsl#L187


    --- .
    SUSE Linux GmbH. Geschäftsführer: Felix Imendörffer, Jane Smithard,
    Graham Norton. HRB 21284 (AG Nürnberg).




  • 2.  RE: [docbook-apps] user-defined text/background color in HTML output

    Posted 08-15-2016 15:04
    Thank you again, Stefan!

    Yes, I solved the problem of extracting the exact color codes using substring-before and substring-after, so this is not a problem.

    I will try to explain again.

    The default template for <phrase> creates
    some text
    in HTML output.

    If we specify the role "color:red;" for a <phrase>, then by default the following output will be created:
    some text

    I should probably avoid creating a new class by specifying phrase.propagates.style=0. Then even with role="color:red;" the output will look like
    some text


    I can extract this "red" from the role's value, and I don't care about the class name (because I'm not going to define a new style in CSS).
    But the question is, how to add a *style* to the using stylesheet customization at all?


    --
    Ekaterina Shikareva.





  • 3.  Re: [docbook-apps] user-defined text/background color in HTML output

    Posted 08-15-2016 15:58
    Hi Ekaterina,
    I agree that trying to use @class and CSS is not the right approach for
    this requirement, because you can have arbitrary combinations of colors.

    In the earliest versions of DocBook there were many templates that
    emitted @style attributes. But over time, those have been eliminated in
    favor of using @class and CSS, which is the recommended practice in general.

    In your case, you could repurpose an existing template to also output a
    style attribute. In the template that matches "phrase" in the
    html/inline.xsl stylesheet module, you can see that there is a call to:

    <xsl:call-template name="locale.html.attributes"/>

    This template is called by all elements to output a @lang attribute if
    needed. It is defined in html/html.xsl to apply-templates in
    mode="locale.html.attributes", so that it can be customized per element.
    The default template for all elements is in html/html.xsl and looks
    like this:

    <xsl:template match="*" mode="locale.html.attributes">
    <xsl:call-template name="generate.html.lang"/>
    <xsl:call-template name="dir"/>
    <xsl:call-template name="its.attributes"/>
    </xsl:template>

    I would suggest adding to your customization layer a template in this
    mode for phrase that looks something like this:

    <xsl:template match="d:phrase" mode="locale.html.attributes">
    <xsl:call-template name="generate.html.lang"/>
    <xsl:call-template name="dir"/>
    <xsl:call-template name="its.attributes"/>
    <xsl:call-template name="style.attribute"/>
    </xsl:template>

    That outputs any locale-related attributes as needed, and then calls a
    template named "style.attribute". Then create a template named
    "style.attribute" that parses your role values and outputs:

    <xsl:attribute name="style">
    [the parsed style string goes here]
    </xsl:attribute>

    Let me know if this doesn't work for you.

    Bob Stayton
    Sagehill Enterprises
    bobs@sagehill.net

    On 8/15/2016 8:04 AM, Shikareva, Ekaterina wrote:
    > Thank you again, Stefan!
    >
    > Yes, I solved the problem of extracting the exact color codes using substring-before and substring-after, so this is not a problem.
    >
    > I will try to explain again.
    >
    > The default template for <phrase> creates
    > some text
    > in HTML output.
    >
    > If we specify the role "color:red;" for a <phrase>, then by default the following output will be created:
    > some text
    >
    > I should probably avoid creating a new class by specifying phrase.propagates.style=0. Then even with role="color:red;" the output will look like
    > some text
    >
    >
    > I can extract this "red" from the role's value, and I don't care about the class name (because I'm not going to define a new style in CSS).
    > But the question is, how to add a *style* to the using stylesheet customization at all?
    >
    >
    > --
    > Ekaterina Shikareva.
    >
    >
    >


  • 4.  RE: [docbook-apps] user-defined text/background color in HTML output

    Posted 08-15-2016 16:26
    Hello, Bob!

    Thank you very much for your detailed answer.

    For now, I've solved my problem by parsing the role's value and constructing the value for <xsl:attribute name="style"> inside <xsl:template match="phrase"> (in my customization layer).
    I mean, I copied the existing <xsl:template match="phrase"> from \docbook-xsl-1.78.1\html\inline.xsl to my customization layer and added a <xsl:choose> block inside it to do the parsing and styling job. In my customization layer, I haven't removed any other lines from the existing template.

    The result looks good in my HTML output :)

    Do you think it is an acceptable solution, or is it better to follow the way you described in your previous message with creating a template named "style.attribute", etc.?


    P.S.: And let me thank you for your amazing guide to DocBook XSL; it helps me immensely in my everyday work!


    P.P.S.: While I'm at it, may I mention something that looked like a small bug in the stylesheets for FO output?
    In docbook-xsl-1.78.1\fo\table.xsl, for table rows you can see:

    <xsl:template name="table.row.properties">
    ...

    <xsl:variable name="bgcolor">
    <xsl:call-template name="pi.dbfo_bgcolor"/>
    </xsl:variable>

    <xsl:if test="$bgcolor != ''">
    <xsl:attribute name="background-color">
    <xsl:value-of select="$bgcolor"/>
    </xsl:attribute>
    </xsl:if>

    ...
    </xsl:template>

    For me adding a background color to table row hadn't worked until I extended the template call:

    <xsl:variable name="bgcolor">
    <xsl:call-template name="pi.dbfo_bgcolor">
    <xsl:with-param name="node" select="ancestor-or-self::row"/>
    </xsl:call-template>
    </xsl:variable>

    Is really a bug, or have I misunderstood something and made a hack instead of fix?


    Thank you very much!

    --
    Ekaterina Shikareva.