[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Converting a string to small-caps?

Subject: Converting a string to small-caps?
From: "Brook Elgie" <brook.elgie@xxxxxxx>
Date: Wed, 15 May 2002 17:27:13 +0100
string caps
The CSS font-variant: small-caps doesn't render as expected in most
browsers( ie. in IE 5.x it renders all the characters as upper-case, and
NN4.x doesn't format it at all). So I'm trying to write a bit of xsl that
does it better. Here's what I've come up with so far:


#### XSL ####
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="html"/>
     <xsl:template match="main">
          <xsl:call-template name="cap">
               <xsl:with-param name="data" select="convert_me"/>
          </xsl:call-template>
     </xsl:template>

     <xsl:template name="cap">
          <xsl:param name="data"/>
           <xsl:if test="$data">
                <xsl:variable name="first_letter"
select="substring($data,1,1)"/>
                <xsl:variable name="upperCase"
select="translate($first_letter,'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMN
OPQRSTUVWXYZ')"/>
                <xsl:choose>
                    <!-- IF THE LETTER IS IN UPPERCASE, LEAVE IT AS IT
IS. -->
                     <xsl:when test="$first_letter = $upperCase">
                          <xsl:value-of select="$upperCase"/>
                     </xsl:when>
                       <!-- OTHERWISE (IF THE LETTER IS IN LOWERCASE),
SHRINK IT A TOUCH-->
                     <xsl:otherwise>
                          <span style="font-size:smaller">
                               <xsl:value-of select="$upperCase"/>
                          </span>
                     </xsl:otherwise>
                </xsl:choose>
                <xsl:call-template name="cap">
                     <xsl:with-param name="data"
select="substring($data,2)"/>
                </xsl:call-template>
           </xsl:if>
     </xsl:template>
</xsl:stylesheet>
#################

Which transforms this:

###### XML #######
<?xml version="1.0" encoding="UTF-8"?>
<main>
     <convert_me>This is the First Sentence.</convert_me>
</main>
#################

as expected into this:

######## HTML #############
T<span style="font-size:smaller">H</span><span
style="font-size:smaller">I</span><span style="font-size:smaller">S</span>
<span style="font-size:smaller">I</span><span
style="font-size:smaller">S</span> <span
style="font-size:smaller">T</span><span
style="font-size:smaller">H</span><span style="font-size:smaller">E</span>
F<span style="font-size:smaller">I</span><span
style="font-size:smaller">R</span><span
style="font-size:smaller">S</span><span style="font-size:smaller">T</span>
S<span style="font-size:smaller">E</span><span
style="font-size:smaller">N</span><span
style="font-size:smaller">T</span><span
style="font-size:smaller">E</span><span
style="font-size:smaller">N</span><span
style="font-size:smaller">C</span><span style="font-size:smaller">E</span>.
#########################

Which renders exactly as expected - but it's hardly efficient to have a span
tag around every letter that I want small!

Is there another way? either tweaking my script or a completely different
way.

cheers
brew



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


Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
Email
First Name
Last Name
Company
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.