|
[XSL-LIST Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] RE: determine the number of payment methods and specif
Caroline,
Here's a first stab at narrowing down your problem.
- You have three <li> elements that are being output in any scenario, and only
the class of each is changing between them. So it sounds like you really just
want to:
- push the switching-logic down into the class template
- automate which <li> elements are created, based on the number of payment
methods specified in the input.
- Pulling the Direct Debit/Credit Card/Invoice parts out to some elements
global to the template might help reduce the amount of <xsl:choose> blocks
here.
- Also, you're not showing us where the checkOutProgressStep template is being
called, so we have to guess.
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:html="http://www.w3.org/1999/xhtml" xmlns:my="my-dummy-namespace"
exclude-result-prefixes="my">
...
<my:paymentMethod label="directDebit" order="1">Direct
Debit</my:paymentMethod>
<my:paymentMethod label="creditCard" order="2">Credit
Card</my:paymentMethod>
<my:paymentMethod label="invoice" order="3">Invoice</my:paymentMethod>
<xsl:variable name="paymentMethods" select="document('')//my:paymentMethod"
/>
<xsl:template name="checkOutProgressStep">
<xsl:param name="label"/>
<xsl:variable name="noOfNodes" select="count(/order/paymentMethods/*)" />
<xsl:variable name="currentMethod" select="$paymentMethods[@label = $label]"
/>
<xsl:for-each select="$paymentMethods[@order <= $noOfNodes]">
<li>
<xsl:attribute name="class">
<xsl:text>doubleLine</xsl:text>
<xsl:if test="@order < $currentMethod/@order"> completed</xsl:if>
<xsl:if test="@order = $currentMethod/@order"> current</xsl:if>
</xsl:attribute>
<xsl:text>Payment by </xsl:text>
<br />
<xsl:value-of select="." />
</li>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
Hope that helps.
~ Scott
-----Original Message-----
From: Caroline Umali [mailto:carolineumali@xxxxxxxxx]
Sent: Monday, November 03, 2008 6:09 PM
To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
Subject: Re: determine the number of payment methods and specify order
depending on page type being viewed
Hi,
Sorry...first time in posting here...ok, so here's an amended version of
the XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:html="http://www.w3.org/1999/xhtml">
...
<xsl:template name="checkOutProgressStep">
<xsl:param name="label"/>
<xsl:variable name="noOfNodes" select="count(/order/paymentMethods/*)" />
<xsl:choose>
<xsl:when test="$noOfNodes = '3'"><!-- check for 3 elements -->
<xsl:choose>
<xsl:when test="$label = 'directDebit'">
<li class="doubleLine current">Payment by <br/>Direct
Debit</li>
<li class="doubleLine">Payment by <br/>Credit Card</li>
<li class="doubleLine">Payment by <br/>Invoice</li>
</xsl:when>
<xsl:when test="$label = 'creditCard'">
<li class="doubleLine completed">Payment by <br/>Direct
Debit</li>
<li class="doubleLine current">Payment by <br/>Credit
Card</li>
<li class="doubleLine">Payment by <br/>Invoice</li>
</xsl:when>
<xsl:when test="$label = 'invoice'">
<li class="doubleLine completed">Payment by <br/>Direct
Debit</li>
<li class="doubleLine completed">Payment by <br/>Credit
Card</li>
<li class="doubleLine current">Payment by <br/>Invoice</li>
</xsl:when>
</xsl:choose>
</xsl:when>
</xsl:choose>
</xsl:template>
...
</xsl:stylesheet>
You'll notice that for the current payment method (specified in the
xsl:when test="..."), the class "current" is added. If a payment method
exists before the current one, then this will have a class "completed",
whereas any subsequent to the current matching payment will have no
extra class.
The method above is only for checking if all three payment types are
present. I haven't even approached checking for 2 payment types or 1,
as I don't even know where to begin.
Apologies if this confusing, as I've been staring at it all day, and
appreciate any tips on bug fixing.
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|

Cart








