Search code examples
xmlxsltbiztalkbiztalk-2010

XSLT select value of if value in node exists


I would like to know if it is possible to select a value with XLST if a value in a node is found. I don't have any experience with XSLT but I need this for a process in Microsoft BizTalk.

So an example of what I would like to do:

<STF_11_OfficeHomeAddress>
     <AD_0_StreetAddress>Street 1</AD_0_StreetAddress>
     <AD_1_OtherDesignation>AD_1_OtherDesignation_0</AD_1_OtherDesignation>
     <AD_2_City>City 1</AD_2_City>
     <AD_3_StateOrProvince>Provence 1</AD_3_StateOrProvince>
     <AD_4_ZipOrPostalCode>ZIP 1</AD_4_ZipOrPostalCode>
     <AD_5_Country>Country 1</AD_5_Country>
     <AD_6_AddressType>TYPE 1</AD_6_AddressType>
    <AD_7_OtherGeographicDesignation>OtherGeographicDesignation 1</AD_7_OtherGeographicDesignation>
</STF_11_OfficeHomeAddress>
<STF_11_OfficeHomeAddress>
    <AD_0_StreetAddress>Street 2</AD_0_StreetAddress>
    <AD_1_OtherDesignation>OtherDesignation 2</AD_1_OtherDesignation>
    <AD_2_City>City 2</AD_2_City>
    <AD_3_StateOrProvince>Province 2</AD_3_StateOrProvince>
    <AD_4_ZipOrPostalCode>Zip 2</AD_4_ZipOrPostalCode>
    <AD_5_Country>Country 2</AD_5_Country>
    <AD_6_AddressType>AddressType 2</AD_6_AddressType>
    <AD_7_OtherGeographicDesignation>OtherGeographicDesignation 2</AD_7_OtherGeographicDesignation>
</STF_11_OfficeHomeAddress>

If value <AD_7_OtherGeographicDesignation>OtherGeographicDesignation 2</AD_7_OtherGeographicDesignation> exists, select <AD_0_StreetAddress>Street 2</AD_0_StreetAddress>. The only thing is, the sequence is not always the same and node <STF_11_OfficeHomeAddress> can occur 11 times in the same file.

Can someone help me please?


Solution

  • //STF_11_OfficeHomeAddress[
      AD_7_OtherGeographicDesignation = 'OtherGeographicDesignation 2'
    ]/AD_0_StreetAddress
    

    Reads as

    • of any office/home address... (//STF_11_OfficeHomeAddress)
    • ...that has its other geographic designation at a certain value... ([AD_7_OtherGeographicDesignation = 'OtherGeographicDesignation 2'])
    • ...select the street address. (/AD_0_StreetAddress)