xsl-list
[Top] [All Lists]

Re: Strings Comparison Question.

2003-01-16 11:51:39
Hi Viral,

At 11:13 AM 1/16/2003, you wrote:
1. Is it possible to compare two strings lexicographically in XSL/XPATH? I
believe the answer is no. Is there a way I can achieve this?

You are correct, the answer is no; XSLT runs up against internationalization / localization requirements here that are hard or impossible to specify in the general case. Its support of extension functions is precisely to help developers bridge this gap.

2. I have listed the XML & XSL below.   In that the community name attribute
could start with a alphabet, a number or any other character.   Most of the
community names are expected to start with alphabets.  In my output, if I
have one or more community name starting with a certain alphabet (i.e. 'A')
then I want to put a link (aka advance orgranizer) at the top of the page
that would say 'A' and likewise for all the alphabets.  Also since I have
few communities starting with non-alphabets, I would want to put a link
called Miscellaneous that would link to a page which would display all
non-alphabetic characters.

How would I go about doing this?  And the those non-alphabetic characters
are not fixed, they could vary depending on the XML file used.  If there was
string comparison allowed then I could do something like @name<'a' or
@name>'z'  for each node and that would give me all non-alphabetic
characters.

This is problem is complex enough that it may require multiple passes. It basically amounts to a large sorting / grouping problem.

But as a start, below your code

<xsl:if test="starts-with(@name,'*')">
  <xsl:call-template name="createTopLetterLinkForCommunity">
    <xsl:with-param name="letterLink">*</xsl:with-param>
  </xsl:call-template>
</xsl:if>

could certainly be pulled out into a template to be called with a parameter of its own (or even rolled into the 'createTopLetterLink' template).

In lieu of hard-coding, you can identify the characters you need to send in as parameters by iterating over your data and using grouping logic (e.g. the Muenchian method -- see the archives) to de-duplicate. (The necessity of doing this is why multiple passes, or the node-set extension function, will be necessary.)

Check the list archives, the XSL FAQ or www.jenitennison.com for more on grouping.

I know this isn't a full solution, but maybe it's enough to get you rolling again.

Cheers,
Wendell


======================================================================
Wendell Piez                            
mailto:wapiez(_at_)mulberrytech(_dot_)com
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================


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