Re: [xsl] Converting a string to Uppercase or Lowercase without using translate() ?

Subject: Re: [xsl] Converting a string to Uppercase or Lowercase without using translate() ?
From: "Andrew Welch" <andrew.j.welch@xxxxxxxxx>
Date: Tue, 27 Nov 2007 15:14:07 +0000
On 27/11/2007, G. Ken Holman <gkholman@xxxxxxxxxxxxxxxxxxxx> wrote:
> I suppose ... I guess I see the problem as a lexical issue and not an
> algorithmic issue.  I cannot comment on optimization opportunities
> for XSLT engines when faced with an explicit string or a variable
> reference ... perhaps someone on the list can comment on this.
> Would you tackle the following with a variable as well?
> <!DOCTYPE xsl:stylesheet [
>     <!ENTITY nbsp '&#xa0;'>
> ]>
> <xsl:stylesheet xmlns:xsl="";
>                   version="1.0">
>   . . . . . &nbsp; . . . . .

I use #160's... I guess I'm relatively young in the markup world (just
turned 29) so I've never really used entities much, especially to the
point where I'd prefer nbsp to it's actual value.

I really don't like doctype declarations at the top of my stylesheets,
but I don't like the use of entities in general.  I'm not too sure
why, but I think it might have come from hunting through ent files for
the definition using something like Notepad.  I've not had positive
experience with DTDs or entities (or default values) where I've
thought - "wow thats a good idea".  Perhaps I've not enountered them
enough in the wild, or the few that I have come across haven't been
done well.

> I don't think people new to XSLT should forget that we are, after
> all, working with XML files.

We are, but I think defining entities at the top of your stylesheet is
an abuse of the fact that XSLT is written in XML, rather than using it
in your favour.

You could for example, counter XSLTs verbosity with some entities:

<!ENTITY f-sib 'following-sibling'>


<xsl:value-of select="//a/&f-sib;::b"/>

to get all of the <b> following-siblings of <a>.

or perhaps "manage" your namespaces:

<!ENTITY xslt-ns ''>

<xsl:stylesheet xmlns="&xslt-ns;" version="2.0">

I know I'm being silly now...

Andrew Welch

Current Thread