Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 16th, 2006, 07:50 AM
Authorized User
 
Join Date: Dec 2004
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default Proper Case IN Xsl

Help
How to make Proper case in xsl

 
Old March 16th, 2006, 08:48 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

How to ask questions that people can understand

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old March 16th, 2006, 10:28 AM
Authorized User
 
Join Date: Dec 2004
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have an string in xml which is in Upper case in XSl i have to dispaly it but in proper case

Example :<NODE1>THIS IS MY STRING</NODE1>
It should Display Like this: This Is My String



 
Old March 16th, 2006, 10:53 AM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

I wasn't familiar with this use of "proper case".

Publisher's rules vary in different languages. Some American newspapers, particularly the more "old-fashioned" sort, seem to use leading upper-case on all words except "a" and "the"; in England upper-case letters are generally used only on nouns and perhaps on longer verbs.

I'm not aware of any publisher who capitalizes every word, but if that's what you want to do, then in XPath 2.0 you can use tokenize() to split the string into words, and substring() and upper-case()/lower-case() to change the case.

In 1.0, use the tokenize() template from the EXSLT library, and use
translate("ABCDE...", "abcde...") for case conversion, assuming all your text is ASCII-only.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old March 16th, 2006, 04:12 PM
Authorized User
 
Join Date: Nov 2004
Posts: 81
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via ICQ to jkmyoung
Default

I believe it's more commonly referred to as Title Case

 
Old March 17th, 2006, 08:29 AM
Authorized User
 
Join Date: Dec 2004
Posts: 37
Thanks: 0
Thanked 0 Times in 0 Posts
Default

There is not any solution to that till now

 
Old March 31st, 2006, 04:18 PM
Registered User
 
Join Date: Mar 2006
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by Israr
 There is not any solution to that till now

Hi All,
Here is a solution:

<xsl:template name="TitleCase">
      <xsl:param name="text" />
      <xsl:param name="lastletter" select="' '"/>
      <xsl:if test="$text">
         <xsl:variable name="thisletter" select="substring($text,1,1)"/>
         <xsl:choose>
            <xsl:when test="$lastletter=' '">
               <xsl:value-of select="translate($thisletter,'abcdefghijklmnopqrs tuvwxyz','ABCDEFGHIJKLMNOPQRSTUVWXYZ')"/>
            </xsl:when>
            <xsl:otherwise>
               <xsl:value-of select="$thisletter"/>
            </xsl:otherwise>
         </xsl:choose>
         <xsl:call-template name="TitleCase">
            <xsl:with-param name="text" select="substring($text,2)"/>
            <xsl:with-param name="lastletter" select="$thisletter"/>
         </xsl:call-template>
      </xsl:if>
   </xsl:template>

 Sample usage:

<xsl:call-template name="TitleCase">
       <xsl:with-param name="text"
          select="translate(normalize-space(text()),'ABCDEFGHIJKLMNOPQRSTUVWXYZ','abcdef ghijklmnopqrstuvwxyz')"/>
      </xsl:call-template>

(Mailing list of apache has discussed about this while ago...)

Regards,
Mohan

 
Old March 31st, 2006, 05:15 PM
mhkay's Avatar
Wrox Author
 
Join Date: Apr 2004
Posts: 4,962
Thanks: 0
Thanked 292 Times in 287 Posts
Default

Well, it might be a solution.

Here is a solution:


It won't produce "Title Case Conversion in XSLT" as its output, it will produce "Title Case Conversion In XSLT", which looks pretty ugly to me. But it it's what you want, go with it.

Michael Kay
http://www.saxonica.com/
Author, XSLT Programmer's Reference and XPath 2.0 Programmer's Reference
 
Old April 4th, 2006, 01:39 PM
Registered User
 
Join Date: Apr 2006
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Well if your output is CSS, you can use CSS functionality to convert the case to Title Case. Just my $0.02






Similar Threads
Thread Thread Starter Forum Replies Last Post
xsl:output with encoding and UPPER case entity ROCXY XSLT 1 April 19th, 2007 08:20 AM
change to proper case in javascript crmpicco Javascript How-To 4 September 22nd, 2005 09:54 AM
change to Proper Case in ASP crmpicco Classic ASP Basics 2 September 12th, 2005 10:33 AM
search string either Upper case or lower case rylemer Beginning VB 6 3 March 24th, 2004 04:23 PM
Check Case in a Case-Insensitive DB nbryson SQL Language 1 January 23rd, 2004 07:36 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.