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

Re: having a template remember not to call itself agai

Subject: Re: having a template remember not to call itself again
From: "Joel Kalvesmaki director@xxxxxxxxxxxxx" <xsl-list-service@xxxxxxxxxxxxxxxxxxxxxx>
Date: Mon, 6 Mar 2023 04:33:57 -0000
Re:  having a template remember not to call itself agai
When I've reached such quandaries in the past, every time, without exception, I eventually learn that I had been overthinking/overengineering the problem. Some time off from the project helps me find a simpler, more elegant approach. Sometimes I replicate the problem on paper or with playing cards. Self-observation on how I do the task manually helps me simplify the code.

One principle I've personally adopted is to ban intentional template recursion. I put any recursion into functions (or an xsl:iterate structure). A function can provide stronger encapsulation than a template mode, and provides certain opportunities to diagnose problems.

A second principle I follow is to have templates call each other in a linear sequence (or, if you will, a directed acyclic graph), and to give them names that reminds me of the order within the sequence. If template mode step six has to call mode step one, I almost always know there is something wrong in my design. Something should be done in step 1, or before it, to avoid such a need.

In a code library I maintain, I have an exception where two template modes interact with each other, and I regret that I have not found an adequate replacement, because it is one of the hardest things for me to diagnose and debug. And I don't fully understand what I've made.

jk

On 2023-03-05 09:20, Chris Papademetrious christopher.papademetrious@xxxxxxxxxxxx wrote:
Hi everyone,

When a template applies its processing first then calls other
templates last, I will call it "tail-call" template chaining (although
I don't know the correct term).

For "tail-call" chaining to work, PROCESSING1_HERE must transform the
content so that CONDITION1_HERE is not met again (or at least not met
in a way that loops infinitely).

But, what if PROCESSING1_HERE is very complex (nested moded templates,
recursion, etc.) and sometimes CONDITION1_HERE will match after this
template was previously applied, and there is no practical way to
embed the complexity of predetermining PROCESSING1_HERE's failure to
remove the condition into CONDITION1_HERE's match expression?

-- Joel Kalvesmaki Director, Text Alignment Network http://textalign.net

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.