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

Re: XSLT function for title capitalization?

Subject: Re: XSLT function for title capitalization?
From: "David Sewell dsewell@xxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Tue, 10 Apr 2018 15:13:39 -0000
Re:  XSLT function for title capitalization?
I am currently using a function similar to this but with some elaboration. The problem, as Liam pointed out in his response, is that the rules for headline/title capitalization that I am targeting are hard to express algorithmically, as they involve decisions about grammatical function, position in the title, internal punctuation ("O'Reilly", etc.) and more.

David

On Tue, 10 Apr 2018, Flanders, Charles E (US) charles.flanders@xxxxxxxxxxxxxx wrote:

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@xxxxxxxxxxxx [mailto:xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx]
Sent: Monday, April 09, 2018 4:53 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject:  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@xxxxxxxxxxxx   Tel: +1 434 924 9973
Web: http://www.upress.virginia.edu/rotunda



-- David Sewell Manager of Digital Initiatives The University of Virginia Press Email: dsewell@xxxxxxxxxxxx Tel: +1 434 924 9973 Web: http://www.upress.virginia.edu/rotunda

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.