last day (15 days later) » 

6:15 PM
0
A: How to change both foreground and background color for an inline element?

Mathias MüllerFirst of all, yes, if there is an ambiguous rule match in an XSLT stylesheet, the most recent (i.e. the last) template is selected. Much of this answer is an outright guess, because we don't see much of the input or XSLT code. But it seems separate templates are not well-suited to handle this....

 
@KevinBrown Thanks for your feedback - yes, that would perhaps be a more sensible solution - but since we do not know more about the XML structures I'll leave my answer as is for now. Also, I'm not sure that would save much typing effort or reduce the complexity - because in the named template you'd have to xsl:if all conditions anyway. How would you implement it?
 
@KevinBrown role="foo", in docbook, is an attribute that is turned into class="foo" when transforming to xhtml. It can and does appear in many other elements. But I need the colors only in the command element.
The assumption about color names does not quite hold. My docbook uses f and g followed by 2 hex digits to select one of the 256 xterm colors. Example: role=" f00 ba0 ul it bd ". The xterm colors appear as color="#rrggbb" in the XSL.
 
@Jens Then, why do you show something completely different in the question? How do you currently translate the hex values to RGB, in the simple cases where background and foreground colors do not both appear on the same command element?
@Jens I see you were online but did not respond. I'd really like to help, but you need to react in one way or another.
 
@Matthias It was late night and I had to sleep; and during the day I keep visits short as it is company time; also, my files are only accessible from home. I wrote (actually changed) f99 to fgGreen so the example would be more readable. No good deed goes unpunished it seems.
 
@Jens Then apologies for rushing you. I'm not punishing anyone, I'm saying that answerers cannot guess in what way actual, hidden data is going to affect the solutions put forward.
 
6:16 PM
No problem. I'm grateful someone takes the time and is patient with my underdeveloped XSLT-fu.
What's surprising to me is that XSLT considers both templates "the same" when the contains("...") part is different.
A bit of background, so you can see the whole picture:
I'm writing a docbook document in which I need to markup the contents of a 256 color xterm, with all the attributes like italics, bold etc. When converting to XHTML I can use CSS and style everything with ease. However, the conversion to XSL-FO (and then PDF) is the hard part.
I already thought of circumventing the problem of customizing my xsl-fo stylesheet by not inlining the xterm screen data in the docbook XML, but instead convert it to SVG and then reference the SVG in a <imagedata format="SVG" file="xterm.svg"/>
 
Hi! First, I'll respond to XSLT considering templates "the same":
 
The point of this exercise is to end up with a screendump that's scalable (otherwise I'd make a PNG screenshot).
 
As you know, an XSLT processor takes an XML document as input. For every node in the input tree, it looks for a template that matches. So, the problem is not really two templates being the same, it's two templates that could match this node (with the same priority).
 
Yes, that's what I gathered from your explanations so far. It all makes sense once you understand the mechanics of XSLT. But it's surprising without that understanding. :-)
 
6:31 PM
Now, the actual problem: As far as I can see, there are 256 * 2 templates in your current stylesheet, all matching command?
Just to make sure I understood before moving on
 
Exactly, plus some other customization for chapter titles etc.
Did you see my edited question? It now has this information.
 
Ah, now I see it.. thanks
I was thinking of the following:
If the conversion between the hex and rgb color values is not too difficult, you could implement it in XSLT
 
Probably "dificult". The first 16 are the 16 ANSI colors of the IBM era, followed by a 6x6x6 color cube, followed by a 24 step grayscale ramp...
AND the xterm user is free to define their own color scheme.
So, consider that requirement to be an arbitrary mapping.
 
does defining their own color scheme mean rearranging the colors
only?
 
No, you simply set the xterm resource for 'color234: rgb:XX/YY/ZZ' where you can chose from the full TrueColor set.
 
6:38 PM
I see, so conversion is out of the quesiton
*question
 
I.e. you could have a scheme with 256 gray colors.
Would XSLT 2.0 have a simple solution for this problem?
 
A tricky problem, but you could do the following: Match command, output a fo:inline anyway. Then, call a named template to tokenize the value of the role attribute. Then, for each of those individual parts of role, output an xsl:attribute - and list all options for the values with xsl:if if needed
it would be a lot simpler with XSLT 2.0, mostly because tokenization is easy and all sequences can be iterated over
As far as I can see, there is no way around listing all mappings between the color values, so even using XLST 2.0 would not spare you that
 
Let me rephrase what I understood: use only a single match for command with an arbitrary role attribute. Pick the role value apart, and convert each item (f00, it, ul, bd, ...) with a separate XSLT construct.
 
Give me 5 minutes, I'll show you with a concrete code example that you can look at online
 
That's great! I'll upvote your answer anyway.
BTW, I need to leave and attend a concert tonight. I'll be online sometime tomorrow. Thanks for all your hard work! Dir auch einen schönen Abend.
 
6:50 PM
Danke gleichfalls - schönes Konzert :-)
 
7:00 PM
Hm, the transform site xsltransform.net went offline - so I cannot show you the code right now - I'll do when the site is back online
 

last day (15 days later) »