Solved

Converting node name to Title Case

Posted on 2004-10-07
5
796 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

The Problem How to write an Xquery that works like a SQL outer join, providing placeholders for absent data on the outer side?  I give a bit more background at the end. The situation expressed as relational data Let’s work through this.  I’ve …
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…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

756 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