Press Ctrl / CMD + C to copy this to your clipboard.
This post will be reported to the moderators as potential spam to be looked at
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
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?
It might be a solution but is there a simple way of doing it where my XSLT is retrieving the data?
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')"/>
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
(Deleted - misread your question, it seems...)
/Chriztian
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
My solution does exactly that.
Am getting loads of errors when saving the XSLT... do i just insert this piece of code
I made a test now, and this works:
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE xsl:stylesheet [ <!ENTITY nbsp " "> ]><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"
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
In the above example please note that the line
char[] chars = input.ToCharArray();
was changed to
char[] chars = input.ToLower().ToCharArray();
Thanks Got it working...
However how to i get another Uppercase if I have to come in a situation where I have a space between the name?
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'" />
Thanks Petr
Using translate will convert all the chars to uppercase, not only the first one, and will not convert the rest to lowcase.
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
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)
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); }
Not to keep beating the uComponents drum, we've got ToTitleCase in there too! ;-)
is working on a reply...
Write your reply to:
Upload image
Image will be uploaded when post is submitted
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
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?
It might be a solution but is there a simple way of doing it where my XSLT is retrieving the data?
//fuji
You could add the code in the xslt:
...
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
(Deleted - misread your question, it seems...)
/Chriztian
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
My solution does exactly that.
Am getting loads of errors when saving the XSLT... do i just insert this piece of code
I made a test now, and this works:
Notice the two extra namespaces at the top
Its still giving me the whole nodeName in Uppercase
If I changed this
to
only the first letter of my nodeName is in Lowercase but i only want first letter Uppercase and the rest LowerCase
In the above example please note that the line
char[] chars = input.ToCharArray();
was changed to
Thanks Got it working...
//fuji
However how to i get another Uppercase if I have to come in a situation where I have a space between the name?
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)
Thanks Petr
Using translate will convert all the chars to uppercase, not only the first one, and will not convert the rest to lowcase.
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
You can do that like this
(it can probably be optimized)
You can also use .NET's ToTitleCase method to do this, so the extension above can be shortened to:
Not to keep beating the uComponents drum, we've got ToTitleCase in there too! ;-)
is working on a reply...