[xsl] Re: A question about the expressive power and limitations of XPath 2.0

Subject: [xsl] Re: A question about the expressive power and limitations of XPath 2.0
From: Dimitre Novatchev <dnovatchev@xxxxxxxxx>
Date: Sat, 12 Jan 2002 22:54:20 -0800 (PST)
Hi Jeni,

Thank you very much for your examples -- I was really expecting your help.

> > As I'm just starting to read the latest WDs, I'd greatly appreciate
> > it if somebody could provide examples showing:
> >
> > 1. A problem, which cannot be easily solved by using "for", but
> > which has a natural recursive solution. Calling user-defined
> > functions within an XPath expression must be excluded, as we can do
> > anything (e.g. recursion) within a user-defined function.
> 
> Perhaps the implementation of a math:power function? You can do that
> with recursion using:
> 
> <xsl:function name="math:power">
>   <xsl:param name="base" type="xs:float" select="1" />
>   <xsl:param name="power" type="xs:integer" select="0" />
>   <xsl:result select="if ($power = 0)
>                       then 1
>                       else $base * math:power($base, $power - 1)" />
> </xsl:function>

Yes, a good example.

> 
> Hmm... the thing that for expressions can't do it aggregate values
> over a sequence. An easy one would be a str:concat() function that
> took a sequence as the argument to be concatenated. This could be
> implemented by recursion with:
> 
> <xsl:function name="str:concat">
>   <xsl:param name="strings" type="xs:string*" select="()" />
>   <xsl:param name="concatenated" type="xs:string" />
>   <xsl:result
>     select="if (empty($strings))
>             then $concatenated
>             else concat($concatenated,
>                         $strings[1],
>                         str:concat($strings[position() > 1])" />
> </xsl:function>
> 

I thought that you could achieve concatenation by a simple:

 <xsl:value-of select="$sequence" separator="''"/>

or am I wrong? (of course, this is not "pure XPath")

So, could you please, think about something similar, that really can't be done? It's
really important!


> These are examples that (I think) are *impossible* to achieve using
> the for expression - not sure that was what you were after?
> 
> > 2. A (text processing), which cannot be solved (easily) by using
> > regular expressions. David already mentioned a string enclosed in
> > balanced parenthesis. Another example is a string consisting of
> > equal number of 1-s and 0-s. It is known that any language defined
> > by a CFG but which cannot be defined by a RE. I just need a small,
> > and if possible meaningful, concrete example.
> 
> Well, the regular expression handling that's described currently is so
> under specified that pointing out things it can't do is like... what's
> the phrase?... "shooting fish in a barrel".
> 

Then please, shoot in the barrel for me... :o)


> Are you after examples that indicate the shortfallings in the regular
> expression syntax, the match() or replace() functions as defined or
> something more general that illustrates that regular expressions can't
> be used to process every kind of string?

I just want to be sure that in case I decided to propose something, it would be
based on solid cases that nobody could say could be easily solved doing this or that
from XPath 2.0.

So you see that I really mean it when I say your help is really very important.

Cheers,
Dimitre.


__________________________________________________
Do You Yahoo!?
Send FREE video emails in Yahoo! Mail!
http://promo.yahoo.com/videomail/

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


Current Thread