Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS 

Using XSLT to convert a value to upper or lowercase

This code was copied from XSLT Case Conversion Solution [topxml.com]

Firstly lets place all the letters of the alphabet, lower case and upper case in variables.
<xsl:variable name="lcletters">abcdefghijklmnopqrstuvwxyz</xsl:variable>
<xsl:variable name="ucletters">ABCDEFGHIJKLMNOPQRSTUVWXYZ</xsl:variable>

To then convert our data to upper case we use the translate method, which replaces all the lower case characters with upper case.
<xsl:value-of select="translate($toconvert,$lcletters,$ucletters)"/>

Lower Case Transformation

The lower case transformation is basically the same:
<xsl:value-of select="translate($toconvert,$ucletters,$lcletters)"/>

Create strings for SEO-friendly URLs

this method returns string, which is perfect for SEO-friendly URLs.

features:
- converts every improper character to a hyphen
- returns a lowercase string

I POSTED AN EVEN BETTER METHOD ON MY BLOG: http://tinyurl.com/2vurbq

def create_callname (title)
	title.downcase.gsub(/[^a-z0-9]+/i, '-')
end

Convert extensions of files to lowercase using perl

1. Searches for files having uppercase extensions (can be mixed with numbers and can be multipart eg: TAR.BZ2 ).
It does not detect files whose extensions contain both upper and lower cases. This is intentional, as if you have part of extension lowercase, you probably intentionally left the other part upper case. Changing this behaviour is trivial. Replace that complex (?:[A-Z]*[0-9]*\.*) with a . (a dot).

2. It then converts them to lowercase.

#!/usr/bin/perl
$files=`ls`;
@files=split(/\n/,$files);
foreach (@files) {
    if(/(.*)\.((?:[A-Z]*[0-9]*\.*)+)$/) {
        $name=$1."."."\L$2\E";
        system("mv $_ $name")
    }
}

Looks quite ugly, but this is what I could do with the Perl I know, and more importantly, it works (at least in my case)!
« Newer Snippets
Older Snippets »
Showing 1-3 of 3 total  RSS