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 13:10:42 -0500 |
How about a two-pass solution?
<xsl:template match="paymentMethods"> <xsl:variable name="temp"> <xsl:apply-templates select="directDebit"/> <xsl:apply-templates select="creditCard"/> <xsl:apply-templates select="invoice"/> </xsl:variable> <xsl:apply-templates select="$temp/*" mode="add-class" </xsl:template>
<xsl:template match="directDebit"> <directDebit>Payment by <br/>Direct Debit</directDebit> </xsl:template>
<xsl:template match="creditCard"> <creditCard>Payment by <br/>Credit Card</creditCard> </xsl:template>
<xsl:template match="invoice"> <invoice>Payment by <br/>Invoice</invoice> </xsl:template>
<xsl:template match="*" mode="add-class"> <xsl:variable name="status"> <xsl:choose> <xsl:when test="$label = local-name()">current</xsl:when> <xsl:when test="preceding-sibling::*[local-name() = $label]">completed</xsl:when> <xsl:otherwise/> </xsl:choose> </xsl:variable> <li class="doubleLine {$status}"><xsl:copy-of select="node()"/></li> </xsl:template>
Probably doesn't save many lines of code, and it runs into the 1.0 node-set() restriction, but it strikes me as capturing the logic of the problem a bit better: if a fourth and fifth kind of payment were added, fewer changes would be needed, as the final template has no knowledge of the different kinds of payment.
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 |
---|
|
<- Previous | Index | Next -> |
---|---|---|
RE: [xsl] determine the number of p, Michael Kay | Thread | Re: [xsl] determine the number of p, Caroline Umali |
Re: [xsl] typing the input from wit, Colin Paul Adams | Date | [xsl] Efficently transposing tokeni, Beldaz Jalfrezi |
Month |