Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Fuji Kusaka 2203 posts 4220 karma points
    May 12, 2011 @ 16:21
    Fuji Kusaka
    0

    Getting @nodeName in lowercase

    hi gUYS,

     

    Is there a way of converting my nodename  from uppercase to lowercase?

    That is getting Uppercase Nodename e.g PAGE 1 but publising it Page 1.

     

    //fuji

  • Bogdan 250 posts 427 karma points
    May 12, 2011 @ 16:34
    Bogdan
    1

    uComponents has some xslt extensions, among which for strings there's the method ToProperCase(String): http://ucomponents.codeplex.com/wikipage?title=Strings&referringTitle=Documentation Is this what you're looking for?

  • Fuji Kusaka 2203 posts 4220 karma points
    May 12, 2011 @ 16:37
    Fuji Kusaka
    0

    It might be a solution but is there a simple way of doing it where my XSLT is retrieving the data?

     

    //fuji

  • Bogdan 250 posts 427 karma points
    May 12, 2011 @ 17:00
    Bogdan
    0

    You could add the code in the xslt:

    ...
    xmlns:str="urn:smth:xslt"
    ...
    <msxsl:script language="C#" implements-prefix="str">
    <![CDATA[
    public string ToProperCase(string input)
            {
                if (string.IsNullOrEmpty(input))
                {
                    return string.Empty;
                }
                char[] chars = input.ToCharArray();
                chars[0] = char.ToUpper(chars[0]);
                return new string(chars);
            }
    ]]>
    </msxsl:script>
    and call it like <xsl:value-of select="str:ToProperCase('PAGE 1')"/>

     

  • Kim Andersen 1447 posts 2196 karma points MVP
    May 12, 2011 @ 22:11
    Kim Andersen
    1

    Hi Fuji

    If you want to convert your node name to lowercase you can do something like this:

    <xsl:value-of select="Exslt.ExsltStrings:lowercase(§currentPage/@nodeName)" />

    /Kim A

  • Chriztian Steinmeier 2800 posts 8790 karma points MVP 8x admin c-trib
    May 12, 2011 @ 22:12
    Chriztian Steinmeier
    1

    (Deleted - misread your question, it seems...)

    
    
    

    /Chriztian

     

  • Fuji Kusaka 2203 posts 4220 karma points
    May 13, 2011 @ 09:20
    Fuji Kusaka
    0

    Thanks everyone for the help....

    Well is works but am having the same issue either i used CSS to style it or Kim solution.

    What i want is to convert the nodeName to lowercase but keeping the first Letter in Uppercase

     

    E.g PAGE 1 => Page 1

  • Bogdan 250 posts 427 karma points
    May 13, 2011 @ 09:33
    Bogdan
    0

    My solution does exactly that.

  • Fuji Kusaka 2203 posts 4220 karma points
    May 13, 2011 @ 09:36
    Fuji Kusaka
    0

    Am getting loads of errors when saving the XSLT... do i just insert this piece of code

     

    <msxsl:script language="C#" implements-prefix="str">
    <![CDATA[
    public string ToProperCase(string input)
            {
                if (string.IsNullOrEmpty(input))
                {
                    return string.Empty;
                }
                char[] chars = input.ToCharArray();
                chars[0] = char.ToUpper(chars[0]);
                return new string(chars);
            }
    ]]>
    </msxsl:script>
  • Bogdan 250 posts 427 karma points
    May 13, 2011 @ 10:07
    Bogdan
    0

    I made a test now, and this works:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp "&#x00A0;"> ]>
    <xsl:stylesheet
      version="1.0"
      xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      xmlns:msxml="urn:schemas-microsoft-com:xslt"
      xmlns:msxsl="urn:schemas-microsoft-com:xslt"
      xmlns:str="urn:smth:xslt"
      xmlns:umbraco.library="urn:umbraco.library" xmlns:Exslt.ExsltCommon="urn:Exslt.ExsltCommon" xmlns:Exslt.ExsltDatesAndTimes="urn:Exslt.ExsltDatesAndTimes" xmlns:Exslt.ExsltMath="urn:Exslt.ExsltMath" xmlns:Exslt.ExsltRegularExpressions="urn:Exslt.ExsltRegularExpressions" xmlns:Exslt.ExsltStrings="urn:Exslt.ExsltStrings" xmlns:Exslt.ExsltSets="urn:Exslt.ExsltSets"
      exclude-result-prefixes="msxml umbraco.library Exslt.ExsltCommon Exslt.ExsltDatesAndTimes Exslt.ExsltMath Exslt.ExsltRegularExpressions Exslt.ExsltStrings Exslt.ExsltSets ">


    <xsl:output method="xml" omit-xml-declaration="yes"/>

    <xsl:param name="currentPage"/>

    <xsl:template match="/">

    <xsl:value-of select="str:ToProperCase('PAGE 1')"/>

    </xsl:template>

    <msxsl:script language="C#" implements-prefix="str">
    <![CDATA[
    public string ToProperCase(string input)
            {
                if (string.IsNullOrEmpty(input))
                {
                    return string.Empty;
                }
                char[] chars = input.ToLower().ToCharArray();
                chars[0] = char.ToUpper(chars[0]);
                return new string(chars);
            }
    ]]>
    </msxsl:script>
        
    </xsl:stylesheet>

    Notice the two extra namespaces at the top

    xmlns:msxsl="urn:schemas-microsoft-com:xslt"
    xmlns:str="urn:smth:xslt"
  • Fuji Kusaka 2203 posts 4220 karma points
    May 13, 2011 @ 10:23
    Fuji Kusaka
    0

    Its still giving me the whole nodeName in Uppercase

    If I changed this

     chars[0] = char.ToUpper(chars[0]);

    to

     

     chars[0] = char.ToLower(chars[0]);

    only the first letter of my nodeName is in Lowercase but i only want first letter Uppercase and the rest LowerCase

     

  • Bogdan 250 posts 427 karma points
    May 13, 2011 @ 10:26
    Bogdan
    0

    In the above example please note that the line

    char[] chars = input.ToCharArray();

    was changed to

    char[] chars = input.ToLower().ToCharArray();
  • Fuji Kusaka 2203 posts 4220 karma points
    May 13, 2011 @ 10:44
    Fuji Kusaka
    0

    Thanks Got it working...

     

    //fuji

  • Fuji Kusaka 2203 posts 4220 karma points
    May 13, 2011 @ 10:53
    Fuji Kusaka
    0

    However how to i get another Uppercase if I have to come in a situation where I have a space between the name?

     

     

  • Petr Snobelt 923 posts 1535 karma points
    May 13, 2011 @ 11:17
    Petr Snobelt
    0

    If you wan pure xslt solution check out http://stackoverflow.com/questions/1207098/xslt-stylesheet-changing-text-to-upper-case (btw first answer on google)

    <xsl:template match="/">
     
    <xsl:value-of select="translate(doc, $smallcase, $uppercase)" />
    </xsl:template>
    <xsl:variable name="smallcase" select="'abcdefghijklmnopqrstuvwxyz'" />
    <xsl:variable name="uppercase" select="'ABCDEFGHIJKLMNOPQRSTUVWXYZ'" />

     

     

  • Fuji Kusaka 2203 posts 4220 karma points
    May 13, 2011 @ 11:22
    Fuji Kusaka
    0

    Thanks Petr

  • Bogdan 250 posts 427 karma points
    May 13, 2011 @ 15:27
    Bogdan
    0

    Using translate will convert all the chars to uppercase, not only the first one, and will not convert the rest to lowcase.

  • Fuji Kusaka 2203 posts 4220 karma points
    May 13, 2011 @ 15:52
    Fuji Kusaka
    0

    Thats what i was thinking of. However how is a space interpreted in C#??

     

    A condition can be applied so that after each space the first Char will be a Uppercase and the rest LoweCase right?

     

    Fuji

  • Bogdan 250 posts 427 karma points
    May 13, 2011 @ 16:31
    Bogdan
    0

    You can do that like this


    <msxsl:script language="C#" implements-prefix="str">
    <![CDATA[
    public string ToProperCase(string input)
    {
        if (string.IsNullOrEmpty(input))
        {
            return string.Empty;
        }
        string[] words = input.Split(' ');
        string[] wordsPropper = new string[words.Length];
        int count = 0;
        foreach (string word in words)
        {
                    char[] chars = word.ToLower().ToCharArray();
                    chars[0] = char.ToUpper(chars[0]);
                    wordsPropper[count] = new string(chars);
                    count++;

        }
        return String.Join(" ", wordsPropper);
    }
    ]]>
    </msxsl:script>

     

    (it can probably be optimized)

     


  • Rick Mather 42 posts 124 karma points
    May 13, 2011 @ 16:58
    Rick Mather
    1

    You can also use .NET's ToTitleCase method to do this, so the extension above can be shortened to:

    public string ToProperCase(string input)
    {
      if(string.IsNullOrEmpty(input)) return string.Empty;
      System.Globalization.TextInfo textInfo = new System.Globalization.CultureInfo("", false).TextInfo; input = input.ToLower();
      return textInfo.ToTitleCase(input); }

  • Lee Kelleher 4026 posts 15836 karma points MVP 13x admin c-trib
    May 13, 2011 @ 17:16
    Lee Kelleher
    0

    Not to keep beating the uComponents drum, we've got ToTitleCase in there too! ;-)

Please Sign in or register to post replies

Write your reply to:

Draft