I would like 1 output returned for two types cases. The first case must loop thru nodes to determine if it’s met. Here is the XML:
<in:inputs
xmlns:in="http://www.composite.net/ns/transformation/input/1.0">
<in:result name="GetCart">
<root xmlns="">
<USC_Purchase ProductPrice="95.0000"
PriceRuleID="1810"
PurchaseQuantity="-1.00"
PaymentNotRequiredQuantity="0.00"
PaymentRequiredQuantity="-1.00"
PaymentRequiredTotal="-95.000000"
PurchaseStatus="R"
RefundTotalAllowed="0.00">
<USC_Product_PriceRule
PriceRuleID="1810"
PriceRuleName="Full Attendee"
PriceRulePriority="1"
PriceRuleStatus="A"
WebUserGroups="13CONF-M001"
ExcludeWebUserGroups=""
ProductPrice="95.0000"
ExternalCode=""
PercentOfProductCode=""
OptionID="0"
FriendlyName="Discounted Rate"
StartEndRestrictionID="0"
ClassID="0"
IsHidden="0"/>
</USC_Purchase>
<USC_Purchase ProductPrice="55.0000"
PurchaseQuantity="-4.00"
PaymentNotRequiredQuantity="0.00"
PaymentRequiredQuantity="-4.00"
PaymentRequiredTotal="-220.000000"
PurchaseStatus="R"
RefundTotalAllowed="568.00">
<USC_Product_PriceRule/>
</USC_Purchase>
Here is my unfinished XSLT, which starts at the first USC_Purchase node:
<xsl:choose>
<xsl:when test="@PurchaseStatus='R'
and ($purchase_total*($purchase_total >=0)
- $purchase_total*($purchase_total < 0))
> @RefundTotalAllowed">
We are having issues processing your refund online.
Please contact us for assistance.
</xsl:when>
<xsl:otherwise>
<!-- insert credit card form here -->
</xsl:otherwise>
This works great…only if the first product met those conditions. The other products go unchecked. A for-each loop at the top of the xsl:choose statement would return multiple messages, and also the credit card form if any of the products were passed fine. (grr!)
My question is – is it possible to loop multiple purchase nodes and stop once a single case is met?
Here are the steps (in case my explanation is throwing anyone off):
-
Choose between two outputs (error message and credit card form).
-
For each USC_Purchase node, if ‘X’ condition(s) are met on any node, display the single error message.
-
Otherwise, display credit card form.
If more information is needed please let me know.
edit
sure, purchase_total is determined by the sum of all paymentrequiredtotals, so:
<xsl:variable
name="purchase_total"
select="sum(USC_Purchase/@PaymentRequiredTotal)" />
Ok, I think I finally understand your requirements. Due to its functional nature, XSLTs do not tend to employ “loop until” logic (it can be done, but is generally not employed when another approach is available). Instead, tests are generally applied across all possible targets at once to see if a condition is met for any of them. I believe the following should do what you are looking to do:
To keep the formulas short, first
purchase_total, then its absolute value are determined, and then a test is done to see if any of theUSC_Purchases match the error condition. If so, the error message is shown, and if not, the credit card form is shown.