Solved

Converting node name to Title Case

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
c# advanced xml like string split - Help needed 15 66
c#, split 12 77
Unable to resolve XML http request 4 63
C# SQL BULK INSERT CLASS 5 34
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 …
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

707 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

14 Experts available now in Live!

Get 1:1 Help Now