Solved

Converting node name to Title Case

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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Challenge to XML Gurus, (XML link downloads blank data while data exists) 10 62
SharePoint 2013 Blog Template 2 47
tutorial for ebay api 3 34
write xml in vb.net 2 24
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…
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

778 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