当“信用卡”是付款方式之一时,我正在尝试提取邮政编码。通常有多种付款方式,即信用卡和现金;信用卡和礼品卡;等等。信用卡不一定是第一笔付款,但是决不会允许使用一张以上的信用卡。我想遍历所有付款类型,并且当付款类型值为'CreditCard'时,然后检索邮政编码。如果未使用信用卡,则该值应为null。
根据我的初步研究,看起来我需要嵌套的For-Each,但不一定是IF。我找到了很多解释嵌套的for-for语句的文章和一些显示简单if语句的文章。我还没有找到任何清晰的文章来显示使用这些组合语句从不同节点级别进行检索。这是我这一行的伪代码:
如果...购买/购买/付款/付款/付款/类型='信用卡'则
...购买/购买/付款/付款/付款/地址/邮政编码的值
我尝试过的各种版本在SSIS包中都没有失败,但是没有检索到结果。
XML示例:
<?xml version="1.0" encoding="utf-8"?>
<exportbatch xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<purchases>
<purchase>
<posRef>987654321</posRef>
<locationRef>1234</locationRef>
<totalamount>99.9900</totalamount>
<payments>
<payment>
<amount>50.0000</amount>
<description>Gift Card x-8765</description>
<type>GiftCard</type>
</payment>
<payment>
<amount>19.5200</amount>
<description>some credit card brand x-8765</description>
<brand>some credit card brand</brand>
<type>CreditCard</type>
<address>
<zipcode>65432</zipcode>
</address>
</payment>
</payments>
</purchase>
</purchases>
</exportbatch>
XSLT示例:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="exportbatch">
<purchases>
<xsl:for-each select="purchases/purchase">
<purchase>
<posRef><xsl:value-of select="posRef"/></posRef>
<LocationId><xsl:value-of select="locationRef"/></LocationId>
<TotalAmount><xsl:value-of select="totalamount"/></TotalAmount>
<xsl:for-each select="payments/payment/type">
<xsl:if test="'CreditCard'">
<PaymentZipCode><xsl:value-of select="address/zipcode"/></PaymentZipCode>
</xsl:if>
</xsl:for-each>
</purchase>
</xsl:for-each>
</purchases>
</xsl:template>
</xsl:stylesheet>
备用XSLT示例:
<xsl:for-each select="payments/payment">
<xsl:if test="@type='CreditCard'">
<PaymentZipCode><xsl:value-of select="address/zipcode"/></PaymentZipCode>
</xsl:if>
</xsl:for-each>
我认为您可以:
<xsl:template match="exportbatch">
<purchases>
<xsl:for-each select="purchases/purchase">
<purchase>
<posRef><xsl:value-of select="posRef"/></posRef>
<LocationId><xsl:value-of select="locationRef"/></LocationId>
<TotalAmount><xsl:value-of select="totalamount"/></TotalAmount>
<xsl:variable name="cc" select="payments/payment[type='CreditCard']" />
<xsl:if test="$cc">
<PaymentZipCode><xsl:value-of select="$cc/address/zipcode"/></PaymentZipCode>
</xsl:if>
</purchase>
</xsl:for-each>
</purchases>
</xsl:template>
这将测试payment
其类型是否CreditCard
存在-如果存在,则从那里检索邮政编码。
或者,您可以执行以下操作:
<xsl:template match="exportbatch">
<purchases>
<xsl:for-each select="purchases/purchase">
<purchase>
<posRef><xsl:value-of select="posRef"/></posRef>
<LocationId><xsl:value-of select="locationRef"/></LocationId>
<TotalAmount><xsl:value-of select="totalamount"/></TotalAmount>
<xsl:if test="payments/payment[type='CreditCard']">
<PaymentZipCode><xsl:value-of select="payments/payment/address/zipcode"/></PaymentZipCode>
</xsl:if>
</purchase>
</xsl:for-each>
</purchases>
</xsl:template>
这将进行相同的测试,如果通过,它将检索可以找到的第一个邮政编码。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句