Kumar_y
Kumar_y

Reputation: 239

conditional match for multiple attributes using XSLT

Below is the input 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>

I need to test for incoming request if the value of Buyer and Shipto and Billtoparty can be AGIIS-EBID or EAN.

I did ask similar question before Previous thread

In previous thread the value I was testing was same.

<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')">

My question is how to test the condition for Agency@Buyer, Agency@Shipto, Agency@billtoParty if the value will be AGIIS-EBID or EAN

I mean in the soap request always Buyer,Shipto, billtoparty can have different sequence like Buyer=AGIIS-EBID,Shipto=EAN,billtoparty=AGIIS-EBID or Buyer=EAN,Shipto=EAN,billtoparty=AGIIS-EBID or Buyer=AGIIS-EBID,Shipto=EAN,billtoparty=EAN

I was thinking to do something like this

<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')">

Can anyone please advise for different approach?

Update for the questions.

@michael.hor257k I am sorry.. three agency objects (Buyer, ShipTo and BillToParty), You are correct it can be positive ( AGIIS-EBID or EAN).. If it is positive I need to accept the message, however if its negative I need to reject the message saying @Agency didn't match the AGIIS or EAN for buyer and Shipto and Billparty.

The problem I am facing is Agency objects (Buyer, ShipTo and BillToParty) should match ( AGIIS-EBID or EAN), but in what manner they come I don't know.

Below are the different ways values may get assigned.

Eg: (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')` so on ....

One more thing I want to add I have to check the positive condition for @Agency in Buyer and Shipto and BilltoParty

Upvotes: 0

Views: 131

Answers (2)

michael.hor257k
michael.hor257k

Reputation: 117165

My goal to test every time $Buyer= 'AGIIS-EBID' or 'EAN' and $Shipto= 'AGIIS-EBID' or 'EAN' and $Billto= 'AGIIS-EBID' or 'EAN'

Okay, so why don't you just spell that out as;

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

Upvotes: 1

JohnRC
JohnRC

Reputation: 1371

How about:

<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>

Upvotes: 1

Related Questions