xsl-list
[Top] [All Lists]

Re: [xsl] XSLT function for title capitalization?

2018-04-10 10:06:26
Here is a function that will accomplish what you need.

    <xsl:function name="c:title-case" as="xs:string">
        <xsl:param name="expr"/>
        <xsl:variable name="tokens" select="tokenize($expr,' ')"/>
        <xsl:variable name="titledTokens" select="for $token in $tokens return
            concat(upper-case(substring($token,1,1)),
            lower-case(substring($token,2)))"/>
        <xsl:value-of select="string-join($titledTokens,' ')"/>
    </xsl:function>



-----Original Message-----
From: David Sewell dsewell(_at_)virginia(_dot_)edu 
[mailto:xsl-list-service(_at_)lists(_dot_)mulberrytech(_dot_)com] 
Sent: Monday, April 09, 2018 4:53 PM
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] XSLT function for title capitalization?

*** WARNING ***
EXTERNAL EMAIL -- This message originates from outside our organization.


Wondering if anyone has a serviceable function (preferably in XSLT 2/3 but v1 
is fine if it works) that takes a string as input and returns it with title 
capitalization according to English-language editorial practice (for example, 
Chicago Manual of Style).  So for example

A MEMORANDUM OF UNDERSTANDING ==> A Memorandum of Understanding

WHERE DID THE DRUIDS COME FROM? ==> Where Did the Druids Come From?

BEING FOR THE BENEFIT OF [MR.] KITE ==> Being for the Benefit of [Mr.] Kite

Use case is, as you might guess, processing a lot of titles transcribed as all 
caps, wanting to convert them to standard title case format.

It doesn't have to be perfect, just anything that will minimize the need for 
hand-editing.

David S.

--
David Sewell
Manager of Digital Initiatives
The University of Virginia Press
Email: dsewell(_at_)virginia(_dot_)edu   Tel: +1 434 924 9973
Web: http://www.upress.virginia.edu/rotunda
--~----------------------------------------------------------------
XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
EasyUnsubscribe: http://lists.mulberrytech.com/unsub/xsl-list/1167547
or by email: xsl-list-unsub(_at_)lists(_dot_)mulberrytech(_dot_)com
--~--

<Prev in Thread] Current Thread [Next in Thread>