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

Re: XSLT 2: Best Way to Synthesize Elements Given List

Subject: Re: XSLT 2: Best Way to Synthesize Elements Given List of Tagnames
From: "Dimitre Novatchev dnovatchev@xxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Sat, 5 Nov 2016 18:11:38 -0000
Re:  XSLT 2: Best Way to Synthesize Elements Given List
>> I'd suggest this non-recursive solution:
>
>
> Personally, I classify this approach as recursive:
>
>   <xsl:template match="*">
>     ...
>     <xsl:apply-templates select="*"/>
>     ...
>   </xsl:template>
>

Yes, we are using recursion in XSLT nearly all the time -- without
being actively aware of this.

This is why, when someone speaks of "recursion" in XSLT they don't
mean applying templates (when the job is done by the XSLT processor
following the rules of the XSLT Processing Model).

They mean code that they have to write, that doesn't rely on the XSLT
Processing Model doing the job behind the scenes, and that, if it
follows a data structure, this structure is not a tree -- in our case
and most often this is a sequence.

To put it another way, no one worries about stack-overflow with
applying templates over an XML document or when almost all the work is
being done by the XSLT built-in templates.

What is considered "recursive" is when the programmer explicitly
defines and controls/implements the recursion.

Therefore, to be correct 100% we should use the term "explicit
recursion" to distinguish it from the implicit recursion that happens
most of the time in a typical transformation.

But we, people, are lazy -- thus "explicit recursion" gets cut just to
"recursion".

Another interesting point is that the "non-recursive" solution has a
"guaranteed" maximum call stack depth  -- something that is imposed by
practical limitations and thus "guarantees" "safety" -- our
transformation is as safe as the XSLT processor / XML parser   --- and
if there is a case where the parser's limits are exceeded, "we are not
to blame" :)

This is a major difference from the general "unsafe" recursion.


Sorry if this sounds philosophical -- it is a dark rainy day today.



Cheers,
Dimitre




On Sat, Nov 5, 2016 at 10:10 AM, G. Ken Holman g.ken.holman@xxxxxxxxx
<xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx> wrote:
> At 2016-11-05 16:50 +0000, Dimitre Novatchev dnovatchev@xxxxxxxxx wrote:
>>
>> I'd suggest this non-recursive solution:
>
>
> Personally, I classify this approach as recursive:
>
>   <xsl:template match="*">
>     ...
>     <xsl:apply-templates select="*"/>
>     ...
>   </xsl:template>
>
> ... as it isn't much different than the following:
>
>   <xsl:function name="my:do-children" xmlns:my="urn:X-myFunctions">
>     <xsl:param name="children" as="element()*"/>
>     <xsl:for-each select="$children">
>       ...
>       <xsl:sequence select="my:do-children(*)"/>
>       ...
>     </xsl:for-each>
>   </xsl:function>
>
> But that's just me.
>
> . . . . . . . . Ken
>
>
> --
> Check our site for free XML, XSLT, XSL-FO and UBL developer resources |
> Streaming hands-on XSLT/XPath 2 training @US$45: http://goo.gl/Dd9qBK |
> Crane Softwrights Ltd. _ _ _ _ _ _ http://www.CraneSoftwrights.com/s/ |
> G Ken Holman _ _ _ _ _ _ _ _ _ _ mailto:gkholman@xxxxxxxxxxxxxxxxxxxx |
> Google+ blog _ _ _ _ _ http://plus.google.com/+GKenHolman-Crane/posts |
> Legal business disclaimers: _ _ http://www.CraneSoftwrights.com/legal |
> 



-- 
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
To avoid situations in which you might make mistakes may be the
biggest mistake of all
------------------------------------
Quality means doing it right when no one is looking.
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
-------------------------------------
To achieve the impossible dream, try going to sleep.
-------------------------------------
Facts do not cease to exist because they are ignored.
-------------------------------------
Typing monkeys will write all Shakespeare's works in 200yrs.Will they
write all patents, too? :)
-------------------------------------
Sanity is madness put to good use.
-------------------------------------
I finally figured out the only reason to be alive is to enjoy it.

Current Thread

PURCHASE STYLUS STUDIO ONLINE TODAY!

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.
Email
First Name
Last Name
Company
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.