Solved

Converting node name to Title Case

Posted on 2004-10-07
5
792 Views
Last Modified: 2009-07-29
I currently use <xsl:value-of select=name()" /> to display the required node names; however, these are all lower case and this does not look great when displayed. I'd like to know how to convert the first letter of the node name to upper case.

Thanks
0
Comment
Question by:Neil_Simpson
  • 3
  • 2
5 Comments
 
LVL 15

Expert Comment

by:dualsoul
ID: 12248624
   <xsl:variable name="upperCaseAlpha">
        <xsl:text>ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:text>
    </xsl:variable>
   <xsl:variable name="lowerCaseAlpha">
       <xsl:text>abcdefghijklmnopqrstuvwxyz</xsl:text>
   </xsl:variable>

     <xsl:variable name="alpha" select="translate(substring(substring(name(),1,1),$lowerCaseAlpha,$upperCaseAlpha)" />
      <xsl:variable name="newName" select="concat($alpha,substring(name(),2))" />
 

now name with first uppercase letter is in the newName variable.
       
0
 
LVL 4

Author Comment

by:Neil_Simpson
ID: 12248712
The variable newName has the first letter missing and not uppercase. I copied and pasted your example directly.
0
 
LVL 15

Accepted Solution

by:
dualsoul earned 125 total points
ID: 12248824
it can't be, here is a sample and full xslt:

-----------xml------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<root>
    <abc></abc>
</root>
----------------------------------------------

-------------xslt--------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
    <xsl:template match="/">
        <xsl:for-each select="descendant::*">
            <xsl:call-template name="upperCase"/> <br/>
        </xsl:for-each>
    </xsl:template>
   
   
    <xsl:template name="upperCase">
        <xsl:variable name="upperCaseAlpha">
            <xsl:text>ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:text>
        </xsl:variable>
        <xsl:variable name="lowerCaseAlpha">
            <xsl:text>abcdefghijklmnopqrstuvwxyz</xsl:text>
        </xsl:variable>
        <xsl:variable name="alpha" select="translate(substring(name(.),1,1),$lowerCaseAlpha,$upperCaseAlpha)"/>
        <xsl:variable name="newName" select="concat($alpha,substring(name(.),2))"/>
        <xsl:value-of select="$newName"/>
    </xsl:template>
</xsl:stylesheet>
----------------------------------------------


, and the output is:

Root
Abc


, so please be carefull :)

0
 
LVL 4

Author Comment

by:Neil_Simpson
ID: 12249017
It was your code:

     <xsl:variable name="alpha" select="translate(substring(substring(name(),1,1),$lowerCaseAlpha,$upperCaseAlpha)" />

should have been

     <xsl:variable name="alpha" select="translate(substring(name(.),1,1),$lowerCaseAlpha,$upperCaseAlpha)"/>

as in your second example.
0
 
LVL 15

Expert Comment

by:dualsoul
ID: 12252694
oh...may be, sorry ;)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

The Client Need Led Us to RSS I recently had an investment company ask me how they might notify their constituents about their newsworthy publications.  Probably you would think "Facebook" or "Twitter" but this is an interesting client.  Their cons…
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
In this video I am going to show you how to back up and restore Office 365 mailboxes using CodeTwo Backup for Office 365. Learn more about the tool used in this video here: http://www.codetwo.com/backup-for-office-365/ (http://www.codetwo.com/ba…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

26 Experts available now in Live!

Get 1:1 Help Now