|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] Converting a string to small-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
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








