Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


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

From: "andrew welch" <andrew.j.welch@--------->
To:
Date: 6/1/2006 9:43:00 AM
On 6/1/06, Mukul Gandhi <gandhi.mukul@xxxxxxxxx> wrote:
On 6/1/06, Phillip B Oldham <phillip.oldham@xxxxxxxxxx> wrote:
> Though, thinking about it, I suppose I could do something like the
> following (thanks *Andrew*):
>
> <xsl:template match="/subscriptions/item[renewaldate]">
> <p>Your renewal date for <xsl:value-of select="subscriptionname" /> is:
> <xsl:value-of select="renewaldate" />.</p>
> </xsl:template>
>
> <xsl:template match="/subscriptions/item[not(renewaldate)]">
> <p>Sorry, there has been an error...</p>
> </xsl:template>
>
> Feels weird though, because actions for the same element aren't being
> kept "together" (within the same template), but it does look more useful
> than a return.

I think, you can write



<xsl:template match="/subscriptions/item">
   <xsl:choose>
      <xsl:when test="renewaldate">
         <p>Your renewal date for <xsl:value-of select="subscriptionname" /> is:
         <xsl:value-of select="renewaldate" />.</p>
     </xsl:when>
     <xsl:otherwise>
        <p>Sorry, there has been an error...</p>
     </xsl:otherwise>
</xsl:template>

You could, but one of the great benefits of keeping everything in
individual templates is that you could then override a template with
an importing stylesheet.

For example, if you had the requirement to alter the error message for
a particular customer, all you would need to do is create a new
stylesheet that imports the existing stylesheet:

<xsl:stylesheet ...>
 <xsl:import href="main.xslt"/>
 <xsl:template match="/subscriptions/item[not(renewaldate)]">
   <p> Customer specific error message </p>
 </xsl:template>
</xsl:stylesheet>

You wouldnt have to touch the existing code which means you wouldn't
risk breaking anything for existing customers, wouldn't have to
re-test everything etc.

This, I think, is another good design rule: when a template contains a
choose/when as its only child, separate it out into individual
templates.


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent