[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
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)" /> </xsl:function> 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> 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? Cheers, Jeni --- Jeni Tennison http://www.jenitennison.com/ XSL-List info and archive: http://www.mulberrytech.com/xsl/xsl-list
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|