Subject: Re: [xsl] "Return" from a function? From: "andrew welch" <andrew.j.welch@xxxxxxxxx> Date: Wed, 31 May 2006 12:53:46 +0100 |
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>
<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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
Re: [xsl] "Return" from a function?, David Carlisle | Thread | [xsl] Converting HTML-like to OpenD, Alex Hudson |
RE: [xsl] Numbering Consecutive Nod, Mark Grant | Date | Re: [xsl] [xml] using schemas/xslt/, Nestor Urquiza |
Month |