[xsl] How can I translate a single letter into a letter inside an element?

Subject: [xsl] How can I translate a single letter into a letter inside an element?
From: Chris Loschen <loschen@xxxxxxxxxxxxx>
Date: Thu, 13 Feb 2003 13:33:12 -0500
Hi, all!

Many thanks for all the help you have given me -- this list is a wonderful
resource. Here's my newest puzzle.

My original data uses an <sc> tag to indicate small caps data. Unfortunately,
it seems to assume that a true small caps font will be used to render that data,
because the data in this element is of mixed case. So, for instance, here are
two examples:

Peter Lewis <sc>DPhil</sc>

<sc>figure 1</sc>

As you can see, "figure 1" is clearly supposed to be in small caps (as it would
be using a true small caps font), and "DPhil" should have the "DP" in full-size
caps and the "hil" in small caps (again as it would be using a true small caps

Unfortunately, we cannot use a true small caps font for my output format which is
a form of XHTML (actually OEB). I have a couple of bad options: (a) just reducing
the size but leaving the case alone, which would result in small lowercase letters;
(b) translating all the lowercase letters to caps and reducing the size, which takes
care of the small caps except where they are truly supposed to be full-sized caps,
so that "DPhil" would be a smaller version of "DPHIL".

A more elegant solution would require inserting a full-size span around capital letters
in a smallcaps span and translating the lowercase letters into uppercase so that
"DPhil" would be rendered

<span class="smallcap"><span class="full">DP</span>HIL</span>.

though this would be a workable alternative

<span class="smallcap"><span class="full">D</span><span class="full">P</span>HIL</span>.

That seems like it ought to be doable, but I'd need to replace individual characters
with a string of characters. I've just checked out Jeni Tennison's template for "multiple
string replacements" at http://www.dpawson.co.uk/xsl/sect2/StringReplace.html
and it looks promising -- is that the way I should go? Or is there some simpler
solution? I guess I'm hoping for something like the translate() function, but which lets
me replace the individual character with the character inside the span element.

Thanks in advance!


Texterity ~ XML and PDF ePublishing Services
Chris Loschen, XML Developer
Texterity, Inc.
144 Turnpike Road
Southborough, MA 01772 USA
tel: +1.508.804.3033
fax: +1.508.804.3110
email: loschen@xxxxxxxxxxxxx

XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list

Current Thread