Solved

Converting node name to Title Case

Posted on 2004-10-07
5
798 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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

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 …
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…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

740 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