Font color change within a sentence

Oxygen general issues.
Cloner
Posts: 4
Joined: Tue Jan 19, 2010 12:58 am

Font color change within a sentence

Post by Cloner »

Hi,

This is embarrassing as I'm sure this borders on the most basic of questions but I can't figure it out. I've seen a lot of posts that come very close to what I want but I have yet to decipher the exact manner to effect it; and that is changing the color of the text within some sort of tag command. I understand the use of <emphasis> for emboldening and italics, etc. But I cannot figure out how to change the color of the font within a document for just a few words--like WARNING.

I'm a tech writer and only understand the most basic functions of this but I have come to understand that I probably have to specify a specific function in the CSS file that "recognizes" when I use a certain tag, to then use that colored font. But the examples I've seen don't look like the same "language" structure that's in my CSS file.

Thank you,

Colin

To give you an idea of how outdated I am, the last time I "programmed," it was with punch cards for FORTRAN in college. I'm under the impression things have changed since then!! :D
Radu
Posts: 9420
Joined: Fri Jul 09, 2004 5:18 pm

Re: Font color change within a sentence

Post by Radu »

Hi Colin,

From what I understand you are using your own CSS and XML formats.
You can use CSS to match elements and change the style properties (font, color, border, etc) for the entire text which is contained by that element.
So if you want to change styling for some words they will have to be wrapped in element tags.
For example to change styling for WARNING it will have to be wrapped in a tag which you can then assign from the CSS some styling.
For <warning>WARNING</warning> XML fragments you can write a CSS selector like:

Code: Select all


warning{
color:red;
}
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Cloner
Posts: 4
Joined: Tue Jan 19, 2010 12:58 am

Re: Font color change within a sentence

Post by Cloner »

Hi Radu,

Thank you for your assistance. I think in my haste I didn't fully explain what my setup is--and what follows may not still fully explain what I've got. I use Eclipse 3.5 and have an Ant plugin which I guess is pretty standard.

I'm using DocBook XML v. 4.1.2 which further confuses me as I have no idea how these things tie in together (despite a lot of reading). So after some trial and error I tried to create a .css file (even using an XI: include command in the style sheet file) and that didn't work (although I don't think I created a correct .css file). You put me on the right path though because as I got to the part where I put "red" in the css format, I got a drop-down of all the available colors.

Then I tried this in the .xsl file:

<xsl:template match="redtext">
<xsl:call-template name="inline.charseq"/>
<fo:inline color="#FF7F7F">
</fo:inline>
</xsl:template>

I tried this command <emphasis role="redtext"> in the XML file but it still compiled in italic font (the default when "it" doesn't recognize the command). The reason I did that is the previous "match" command used "bold" for emboldening text--so I assumed I needed to use the same command string. But yep, I tried using <redtext> all by itself and I still got the red X of death since "redtext" wasn't declared.

If I could impose on you for further assistance I'd greatly appreciate it.

Colin
Radu
Posts: 9420
Joined: Fri Jul 09, 2004 5:18 pm

Re: Font color change within a sentence

Post by Radu »

Hi Colin,

Ok, now I understand you want the red WARNING to appear in the generated HTML output.
Using <emphasis role="redtext">WARNING</emphasis> is the right way to do it.
This will generate a HTML output file which contains code like:

Code: Select all

 <span class="redtext">WARNING</span>
So if you associate a CSS to the HTML file which matches the "redtext" class attribute and uses the red color, the HTML will render the warning word with red. The CSS content should be like:

Code: Select all


.redtext{
color:red;
}


You can either associate the path to the CSS file by editing the result HTML or let the Docbook stylesheets associate it.

Here is a link about how the CSS can be automatically associated with the HTML:
http://www.sagehill.net/docbookxsl/UsingCSS.html

Basically you edit the Docbook HTML/XHTML transformation scenario, click the "Parameters" button, edit the html.stylesheet parameter and set its value to the relative CSS file location.
For example if the CSS file is called test.css and is situated in the same directory as the XML source the value should be test.css

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply