home contribute faq download

FunctX XSLT Functions

functx:format-as-title-en

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

Google
Webxsltfunctions.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*

XSLT Function Declaration

See XQuery definition.
<xsl:function name="functx:format-as-title-en" as="xs:string*"
              xmlns:functx="http://www.functx.com">
  <xsl:param name="titles" as="xs:string*"/>

   <xsl:variable name="wordsToMoveToEnd"
                 select="('A', 'An', 'The')"/>
   <xsl:for-each select="$titles">
     <xsl:variable name="title" select="."/>
     <xsl:variable name="firstWord"
          select="functx:substring-before-match($title,'\W')"/>
     <xsl:sequence select="if ($firstWord = $wordsToMoveToEnd)
          then replace($title,'(.*?)\W(.*)', '$2, $1')
          else $title"/>
   </xsl:for-each>

</xsl:function>

Examples

XPath 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 XSLT Services

Recommended Reading:

XQuery