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

RE: Small Caps Solution (a bit long)

Subject: RE: Small Caps Solution (a bit long)
From: <christof.hoeke@xxxxxxx>
Date: Thu, 2 Sep 2004 09:55:35 +0200
html small caps
> Von: Jay Bryant [mailto:jay@xxxxxxxxxxxx]
> Betreff:  Small Caps Solution (a bit long)
>
> After years of raiding the archive for solutions, I am
> finally un-lurking
> and posting my own solution. I wanted to render a string as small caps
> t'other day, but I couldn't find a full solution on the
> Internet.

hi,
if i understand the problem right, there is a much simpler and shorter
solution without even bothering XSL just with plain CSS which you are using
anyway:

	<h1 style="font-variant: small-caps;">A String to Render in Small Caps</h1>

(better to put it in a CSS-class of course...)
This might not be working in every browser, but at least covers a reasonble
amount of them (Moz, IE, Opera, Safari etc).

is that what you were looking for?

cheers
chris




> So, I rolled my own, and here it is. I have included the XML input
> and the HTML
> output (from Saxon 8). I hope no one minds a fairly lengthy post, as I
> wanted to provide full detail.
>
> XML File
> ------------------------------
> <body>
>   <heading1>A String to Render in Small Caps</heading1>
> </body>
> ------------------------------
>
> XSL File
> ------------------------------
>
> <xsl:stylesheet
> version="1.0"
> xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
> >
>   <xsl:template match="/">
>   <html>
>     <head>
>       <title>Small Cap Test</title>
>     </head>
>     <style type="text/css">
>       .smallCapUpper {
>         font-size: Larger
>       }
>       .smallCapLower
>         font-size: Smaller
>       }
>     </style>
>     <body>
>       <h1><xsl:apply-templates/></h1>
>     </body>
>   </html>
>   </xsl:template>
>   <xsl:template match="heading1">
>     <xsl:call-template name="smallCaps">
>       <xsl:with-param name="inString" select="."/>
>     </xsl:call-template>
>   </xsl:template>
>
>   <xsl:template name="smallCaps">
>     <xsl:param name="inString"/>
>     <xsl:variable name="firstLetter"
> select="substring($inString, 1, 1)"/>
>     <xsl:variable name="upperFirst" select="translate($firstLetter,
> 'abcdefghijklmnopqrstuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
>     <xsl:choose>
>       <xsl:when test="$firstLetter = $upperFirst">
>         <xsl:variable name="lowerTest" select="translate($inString,
> 'abcdefghijklmnopqrstuvwxyz', '++++++++++++++++++++++++++')"/>
>         <xsl:choose>
>           <xsl:when test="contains($lowerTest, '+')">
>             <xsl:variable name="upperToRemove"
> select="substring-before($lowerTest, '+')"/>
>             <span class="smallCapUpper"><xsl:value-of
> select="$upperToRemove"/></span>
>             <xsl:call-template name="smallCaps">
>               <xsl:with-param name="inString"
> select="substring-after($inString, $upperToRemove)"/>
>             </xsl:call-template>
>           </xsl:when>
>           <xsl:otherwise> <!-- test="contains($lowerTest, '+')" -->
>             <span class="smallCapUpper"><xsl:value-of
> select="$lowerTest"/></span>
>           </xsl:otherwise>
>         </xsl:choose>
>       </xsl:when>
>       <xsl:otherwise> <!-- test="$firstLetter = $upperFirst" -->
>         <xsl:variable name="upperTest" select="translate($inString,
> 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', '++++++++++++++++++++++++++')"/>
>         <xsl:choose>
>           <xsl:when test="contains($upperTest, '+')">
>             <xsl:variable name="lowerToRemove"
> select="substring-before($upperTest, '+')"/>
>             <span class="smallCapLower"><xsl:value-of
> select="translate($lowerToRemove, 'abcdefghijklmnopqrstuvwxyz',
> 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/></span>
>             <xsl:call-template name="smallCaps">
>               <xsl:with-param name="inString"
> select="substring-after($inString, $lowerToRemove)"/>
>             </xsl:call-template>
>           </xsl:when>
>           <xsl:otherwise> <!-- test="contains($upperTest, '+')" -->
>             <span class="smallCapLower"><xsl:value-of
> select="translate($upperTest, 'abcdefghijklmnopqrstuvwxyz',
> 'ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/></span>
>           </xsl:otherwise>
>         </xsl:choose>
>       </xsl:otherwise>
>     </xsl:choose>
>   </xsl:template>
> </xsl:stylesheet>
> ------------------------------
>
> HTML File
> (I modified the actual output a bit so that it would be
> nicely formatted.
> Otherwise, it's a very long line.)
> ------------------------------
> <html>
>   <head>
>     <meta http-equiv="Content-Type" content="text/html;
> charset=UTF-8">
>     <title>Small Cap Test</title>
>   </head>
>   <style type="text/css">
>     .smallCapUpper {
>       font-size: Larger
>     }
>     .smallCapLower
>       font-size: Smaller
>     }
>   </style>
>   <body>
>     <h1>
>       <span class="smallCapUpper">A S</span>
>       <span class="smallCapLower">TRING TO </span>
>       <span class="smallCapUpper">R</span>
>       <span class="smallCapLower">ENDER IN </span>
>       <span class="smallCapUpper">S</span>
>       <span class="smallCapLower">MALL </span>
>       <span class="smallCapUpper">C</span>
>       <span class="smallCapLower">APS</span>
>     </h1>
>   </body>
> </html>
> ------------------------------
>
> Jay Bryant
> Bryant Communication Services

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.