Re: [xsl] determine the number of payment methods and specify order depending on page type being viewed

Subject: Re: [xsl] determine the number of payment methods and specify order depending on page type being viewed
From: Wendell Piez <wapiez@xxxxxxxxxxxxxxxx>
Date: Tue, 04 Nov 2008 10:38:32 -0500
Caroline,

Just to gloss something I just wrote, in order to make it clear:

At 10:26 AM 11/4/2008, I wrote:
If you want to fix the order of the children of 'paymentMethods', you can do:

<xsl:template match="paymentMethods">
  <ul>
    <xsl:apply-templates select="directDebit"/>
    <xsl:apply-templates select="creditCard"/>
    <xsl:apply-templates select="invoice"/>
  </ul>
</xsl:template>

The deal here is that if you have no 'creditCard' element in your 'paymentMethods', for example, then none will be selected and no template will be applied, hence no 'li' element will be generated for it. This handles all the conditional processing needed, in effect testing whether the 'creditCard' element is present (and creating nothing for it if it isn't).


This is why, using the apply-templates approach to your problem, you don't have to do any explicit testing to see whether all three elements are present, or only two (and which two), or only one (and which one), or none at all.

Also, because the order of their appearance has been fixed (if they are present at all), the possible permutations in assigning the value to the li/@class in the result are also reduced -- which is lucky for you, since those values are themselves sensitive to the order.

Cheers,
Wendell



======================================================================
Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.                http://www.mulberrytech.com
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
----------------------------------------------------------------------
  Mulberry Technologies: A Consultancy Specializing in SGML and XML
======================================================================

Current Thread