home contribute faq download

FunctX XQuery Functions

functx:format-as-title-en

Moves title words like "the" and "a" to the end of strings

Google
Webxqueryfunctions.com

Description

The functx:format-as-title-en function treats a sequence of strings like titles, moving the words "A", "An" and "The" to the end.

Arguments and Return Type

NameTypeDescription
$titles xs:string* the titles to format
return value xs:string*

XQuery Function Declaration

See XSLT definition.
declare namespace functx = "http://www.functx.com";
declare function functx:format-as-title-en
  ( $titles as xs:string* )  as xs:string* {

   let $wordsToMoveToEnd := ('A', 'An', 'The')
   for $title in $titles
   let $firstWord := functx:substring-before-match($title,'\W')
   return if ($firstWord = $wordsToMoveToEnd)
          then replace($title,'(.*?)\W(.*)', '$2, $1')
          else $title
 } ;

Examples

XQuery ExampleResults
functx:format-as-title-en(
     ('A Midsummer Night''s Dream',
      'The Merchant of Venice',
      'Hamlet'))
('Midsummer Night's Dream, A',
 'Merchant of Venice, The',
 'Hamlet'''Midsummer Night's Dream, A',
 'Merchant of Venice, The',
 'Hamlet')

Depends On

functx:substring-before-matchThe substring before the last text that matches a regex

See Also

fn:upper-caseConverts to upper case

History

Published OnLast UpdatedContributor(s)
2006-06-272007-02-26Priscilla Walmsley, Datypic, pwalmsley@datypic.com, http://www.datypic.com
Datypic XQuery Services

Recommended Reading:

XQuery