RE: [xsl] case insensitive attributes

Subject: RE: [xsl] case insensitive attributes
From: "Jay Gardner" <jgardner@xxxxxxxxxxxxxxxxxxxxxx>
Date: Thu, 5 Apr 2001 13:27:45 -0500
Thanks Jeni 

That worked perfectly.

-----Original Message-----
From: Jeni Tennison [mailto:mail@xxxxxxxxxxxxxxxx]
Sent: Thursday, April 05, 2001 11:52 AM
To: Jay Gardner
Cc: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: [xsl] case insensitive attributes


Hi Jay,

Just to clarify - the translate() function takes its first argument as
a string, and changes all the letters in the string given as the
second argument for the corresponding letter in the string given as
the third argument.

> I ended up using this and it seems to be working, but
> I am not sure how efficient it will be.
>
> root/CamUsers[@UserId =
translate(@UserId,'ABCDEFGHIJKLMNOPQRSTUVWXYZ',
> 'abcdefghijklmnopqrstuvwxyz') = 'Admin']

That collects all the CamUsers elements where:

  the fact that the UserId attribute is equal to the lowercase version
  of the UserId attribute (i.e. either true() or false() - false() if
  the UserId has any uppercase letters in it)

  is equal to

  the result of converting the string 'Admin' to a boolean (which is
  always true() as 'Admin' is never an empty string)

So the fact that this is working implies that within your test data,
the CamUsers that you want to select are those whose UserId attributes
contain only lowercase letters.

That might be the case in your sample, but I don't think it was what
you were after.

If the 'Admin' string (i.e. the login name that you want to find the
CamUser for) can vary in case as well, then you need to do the
translation *on both*, so that they're both all lowercase. Using $uc
for uppercase letters and $lc for lowercase ones, this means you want:

   root/CamUsers[translate(@UserId, $uc, $lc) =
                 translate('Admin', $uc, $lc)]

If it's only the 'Admin' string that can change in case (i.e. the
@UserId attributes are always all lowercase), then you want to only
translate the 'Admin' string:

   root/CamUsers[@UserId, translate('Admin', $uc, $lc)]

If the @UserId attributes are always all in uppercase, then you want
to change the login name (e.g. 'Admin') into uppercase:

   root/CamUsers[@UserId, translate('Admin', $lc, $uc)]

I hope that's clearer,

Jeni

---
Jeni Tennison
http://www.jenitennison.com/



 XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list


Current Thread