Re: [xsl] "Return" from a function?

Subject: Re: [xsl] "Return" from a function?
From: "andrew welch" <andrew.j.welch@xxxxxxxxx>
Date: Wed, 31 May 2006 12:53:46 +0100
On 5/31/06, Phillip B Oldham <phillip.oldham@xxxxxxxxxx> wrote:
Hi all

<rant type="pointless" mood="whimsical">

One thing I've found annoying when moving from OOP to functional
programming is the lack of "return". It would be extremely useful to do
something like the following:

<xsl:function match="/subscriptions/item">
<xsl:if test="not(renewaldate)">
     <xsl:return />
</xsl:if>
<!-- otherwise execute the rest of the stuff below -->
</xsl:template>

Can be written as:


<xsl:template match="/subscriptions/item[renewaldate]">
 <!-- code for item with a renewal date -->
</xsl:template>

<1-- no-op template for item without a renewal date -->
<xsl:template match="/subscriptions/item[not(renewaldate)]"/>

Then just apply-templates as normal.  Or use a select on the
apply-templates to only process those items with a renewal date - one
of the fundamentals of XSLT is to only select the nodes you want
process, dont select all nodes and then try and break out.

The main "rule" imho is to always use apply-templates over for-each,
only use for-each to change the context node.  Anyone thinking
procedurally (coming from an OOP background) tends to reach for
for-each first which is fine for very simple stylesheets by causes
problems later, much better to use apply-templates and learn the flow
of execution early on.

Current Thread