使用XSLT对多个属性进行条件匹配

时间:2015-02-27 05:14:12

标签: xslt conditional conditional-statements

下面是输入XML

    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:ces:names:specification:ces:schema:all:4:0">
    <soapenv:Header/>
    <soapenv:Body>
        <ces:ShipNotice Version="4.0" xmlns:ces="urn:ces:names:specification:ces:schema:all:4:0">
            <ces:Header>
                <ces:From>
                </ces:From>
                <ces:To>
                </ces:To>
            </ces:Header>
            <ces:ShipNoticeBody>
                <ces:ShipNoticePartners>
                    <ces:Buyer>
                        <ces:PartnerInformation>
                            <ces:PartnerIdentifier Agency="AGIIS-EBID">8049915600000</ces:PartnerIdentifier>
                        </ces:PartnerInformation>
                    </ces:Buyer>
                    <ces:OtherPartner PartnerRole="ShipTo">
                        <ces:PartnerInformation>
                            <ces:PartnerIdentifier Agency="AGIIS-EBID">8049915600000</ces:PartnerIdentifier>
                        </ces:PartnerInformation>
                    </ces:OtherPartner>
                    <ces:OtherPartner PartnerRole="BillToParty">
                        <ces:PartnerInformation>
                            <ces:PartnerIdentifier Agency="AGIIS-EBID">1024122440000</ces:PartnerIdentifier>
                        </ces:PartnerInformation>
                    </ces:OtherPartner>
                </ces:ShipNoticePartners>
                <ces:ShipNoticeDetails>
                </ces:ShipNoticeDetails>
            </ces:ShipNoticeBody>
        </ces:ShipNotice>
    </soapenv:Body>
</soapenv:Envelope>

如果买方和Shipto和Billtoparty 的值可以 AGIIS-EBID或EAN ,我需要测试收到的请求。

之前我确实问了类似的问题 Previous thread

在前一个帖子中,我测试的值是相同的。

<xsl:when test="
 ($Buyer='AGIIS-EBID' and  $Shipto='AGIIS-EBID' and $Billto='AGIIS-EBID') 
 or ($Buyer='EAN' and  $Shipto='EAN' and $Billto='EAN') 
 or ($Buyer='GLN' and  $Shipto='GLN' and $Billto='GLN')">

如果值 AGIIS-EBID EAN

,我的问题是如何测试Agency@Buyer, Agency@Shipto, Agency@billtoParty的条件

我的意思是在肥皂请求中,总是买方,Shipto,billtoparty可以有不同的序列,如Buyer=AGIIS-EBID,Shipto=EAN,billtoparty=AGIIS-EBID or Buyer=EAN,Shipto=EAN,billtoparty=AGIIS-EBID or Buyer=AGIIS-EBID,Shipto=EAN,billtoparty=EAN

我在考虑做这样的事情

<xsl:when test="($Buyer='AGIIS-EBID' and  $Shipto='AGIIS-EBID' and $Billto='AGIIS-EBID') or ($Buyer='AGIIS-EBID' and  $Shipto='EAN' and $Billto='AGIIS-EBID')($Buyer='AGIIS-EBID' and  $Shipto='AGIIS-EBID' and $Billto='EAN') or ($Buyer='EAN' and  $Shipto='EAN' and $Billto='EAN')">

有人可以建议采用不同的方法吗?

更新问题。

@ michael.hor257k对不起..三个代理对象(买方,ShipTo和BillToParty),你是正确的,它可以是正面的(AGIIS-EBID或EAN)..如果它是肯定的,我需要接受这个消息,但是,如果它的消极,我需要拒绝消息,说@Agency与买方和Shipto和Billparty的AGIIS或EAN不匹配。

我面临的问题是代理商对象(Buyer, ShipTo and BillToParty)应与( AGIIS-EBID or EAN)相匹配,但他们以何种方式来我不知道。

以下是可以分配值的不同方式。

例如:( Buyer='AGIIS-EBID'and Shipto='EAN'and Billtoparty='AGIIS-EBID') or (Buyer='EAN' and Shipto='EAN' and Billtoparty='AGIIS-EBID') or (Buyer='AGIIS-EBID' and Shipto='EAN' and Billtoparty='EAN')`等等......

我要添加的另一件事我必须检查买方和Shipto和BilltoParty

@Agency的正面条件

2 个答案:

答案 0 :(得分:1)

怎么样:

<xsl:variable name="Buyer_ok" select=" $Buyer = 'EAN' or $Buyer = 'AGIIS-EBID' " />
<xsl:variable name="Shipto_ok" select=" $Shipto = 'EAN' or $Shipto = 'AGIIS-EBID' " />
<xsl:variable name="Billto_ok" select=" $Billto = 'EAN' or $Billto = 'AGIIS-EBID' " />
        :
        :
<xsl:when test=" $Buyer_ok and $Shipto_ok and $Billto_ok "> . . .</xsl:when>

答案 1 :(得分:1)

  

我的目标是每次测试$ Buyer ='AGIIS-EBID'或'EAN'和$ Shipto =   'AGIIS-EBID'或'EAN'和$ Billto ='AGIIS-EBID'或'EAN'

好的,那么你为什么不把它拼写为;

<xsl:when test="
($Buyer='AGIIS-EBID' or $Buyer='EAN') 
and 
($Shipto='AGIIS-EBID' or $Shipto='EAN')
and 
($Billto='AGIIS-EBID' or $Billto='EAN')">