我希望为两种类型的情况返回 1 个输出。第一种情况必须循环遍历节点以确定是否满足。这是 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>
这是我未完成的 XSLT,它从第一个 USC_Purchase 节点开始:
<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>
只有当第一个产品满足这些条件时,这才有效。其他产品不受检查。 xsl:choose 语句顶部的 for-each 循环将返回多条消息,如果任何产品顺利通过,还会返回信用卡表单。 (咕噜!)
我的问题是 - 是否可以循环多个购买节点并在满足单个案例后停止?
以下是步骤(以防我的解释让任何人感到困惑):
在两个输出之间进行选择(错误消息和信用卡表单)。
对于每个 USC_Purchase 节点,如果任何节点上满足“X”条件,则显示一条错误消息。
否则,显示信用卡表单。
如果需要更多信息,请告诉我。
编辑
当然,purchase_total 由所有 paymentrequiredtotals 的总和决定,因此:
<xsl:variable
name="purchase_total"
select="sum(USC_Purchase/@PaymentRequiredTotal)" />
最佳答案
好的,我想我终于明白你的要求了。由于其功能性质,XSLT 不倾向于采用“循环直到”逻辑(可以这样做,但当有其他方法可用时通常不采用)。相反,测试通常会立即应用于所有可能的目标,以查看其中任何一个目标是否满足条件。我相信以下内容应该可以满足您的要求:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="root">
<xsl:variable
name="purchase_total"
select="sum(USC_Purchase/@PaymentRequiredTotal)" />
<xsl:variable
name="purchase_total_abs"
select="$purchase_total * (1 - 2 * ($purchase_total < 0))" />
<xsl:choose>
<xsl:when test="USC_Purchase[@PurchaseStatus ='R' and
$purchase_total_abs > @RefundTotalAllowed]">
We are having issues processing your refund online. Please contact us for assistance.
</xsl:when>
<xsl:otherwise>
<xsl:call-template name="CreditCardForm" />
</xsl:otherwise>
</xsl:choose>
</xsl:template>
<xsl:template name="CreditCardForm">
<!-- Credit form-->
</xsl:template>
</xsl:stylesheet>
为了保持公式简短,首先purchase_total
,然后确定其绝对值,然后进行测试以查看是否有任何USC_Purchase
与错误匹配健康)状况。如果是,则显示错误消息,如果不是,则显示信用卡表单。
关于XSLT - 测试每个节点的条件,如果满足条件则中断测试,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14674910/