[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message]

Re: A question about the expressive power and limitati

Subject: Re: A question about the expressive power and limitations of XPath 2.0
From: Jeni Tennison <jeni@xxxxxxxxxxxxxxxx>
Date: Sun, 13 Jan 2002 00:06:24 +0000
empty barrel dimitre
Hi Dimitre,

> 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)" />

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" />
    select="if (empty($strings))
            then $concatenated
            else concat($concatenated,
                        str:concat($strings[position() > 1])" />

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".

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?



Jeni Tennison

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

Current Thread


Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced!

Buy Stylus Studio Now

Download The World's Best XML IDE!

Accelerate XML development with our award-winning XML IDE - Download a free trial today!

Don't miss another message! Subscribe to this list today.
First Name
Last Name
Subscribe in XML format
RSS 2.0
Atom 0.3
Site Map | Privacy Policy | Terms of Use | Trademarks
Free Stylus Studio XML Training:
W3C Member
Stylus Studio® and DataDirect XQuery ™are products from DataDirect Technologies, is a registered trademark of Progress Software Corporation, in the U.S. and other countries. © 2004-2013 All Rights Reserved.