This is the mail archive of the xsl-list@mulberrytech.com mailing list .


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Selecting case insensitively




Hi Jeni,
Thanks for your help. I tried using the key solution and it worked perfectly.
However, I have not been able to get the correct results using the non-key
approach. I changed following to preceding as you suggested. So now my XPath
looks like this:
  Test/location/state[not(translate(.,$lowercase,$uppercase)=
                          translate(preceding::state,$lowercase,$uppercase))]

 When I run the transformation on this input:
<location>
   <state>xxxx</state>
 </location>

 <location>
    <state>yyyy</state>
 </location>

  <location>
    <state>xxxx</state>
 </location>

  <location>
    <state>xxXx</state>
 </location>

 <location>
    <state>yyyy</state>
 </location>

I get this result:
xxxx
yyyy
yyyy

It seems as if the comparison is always with the first element in the input
file.  I would be interested to know why this happens...

Thanks,
Michal

PS I am using the July version of the MSXML parser.



Michal,

>I tried to get "insensitively" unique records from a list and I failed,
what am
>I missing?

Within your template, the XPath you're using to figure out whether the
state is unique or not is:

  Test/location/state[not(translate(.,$lowercase,$uppercase)=
                          translate(following::state,$lowercase,$uppercase))]

In other words: find any states where there isn't a following state that
has the same content as this one (case insensitively).  For the last state
in your list, this will always be true: there are no states that follow
that one, so it's true that there are no states that have the same content
(case insensitive or not!).

As you're working through the list in document order, what you're probably
after is 'preceding' rather than 'following'.  Then, each state will appear
if no state with that name has already appeared.

  Test/location/state[not(translate(.,$lowercase,$uppercase)=
                          translate(preceding::state,$lowercase,$uppercase))]

The other alternative is to use keys to identify unique states.  Index each
of the states according to the key:

<xsl:key name="states" match="state"
         use="translate(., $lowercase, $uppercase)" />

And then retrieve only the unique ones using:

  Test/location/state[generate-id() =
         generate-id(key('states', translate(., $lowercase, $uppercase))[1])]

In other words, is the unique identifier for this state the same as unique
identifier for the first state retrieved using the key.  This will work
more efficiently if you have lots and lots of states in your document (and
if your XSLT processor supports keys).

I hope that this helps,

Jeni



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






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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]