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
[email protected]
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
<span class="phrase">some text</span>
in HTML output.
If we specify the role "color:red;" for a <phrase>, then by default the
following output will be created:
<span class="color:red;">some text</span>
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
<span class="phrase">some text</span>
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 <span> using stylesheet
customization at all?
--
Ekaterina Shikareva.
-----Original Message-----
From: Stefan Knorr [mailto:[email protected]]
Sent: Montag, 15. August 2016 16:41
To: Shikareva, Ekaterina
Cc: [email protected]
Subject: RE: [docbook-apps] user-defined text/background color in HTML output
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).
________________________________
This e-mail and any attachment(s) are intended only for the recipient(s) named
above and others who have been specifically authorized to receive them. They
may contain confidential information. If you are not the intended recipient,
please do not read this email or its attachment(s). Furthermore, you are hereby
notified that any dissemination, distribution or copying of this e-mail and any
attachment(s) is strictly prohibited. If you have received this e-mail in
error, please immediately notify the sender by replying to this e-mail and then
delete this e-mail and any attachment(s) or copies thereof from your system.
Thank you.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]