Reputation: 85
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?
Upvotes: 0
Views: 427
Reputation: 15264
Go through at least the fundamental section of Jeni Tennison's XSLT tutorial pages first, you'll then be able to do this yourself by doing push mode (instead of pull mode) and using a predicate with your matching rule such as:
<xsl:template match="AD_0_StreetAddress[../AD_7_OtherGeographicDesignation]">
<xsl:value-of select="."/>
Upvotes: 1
Reputation: 338108
//STF_11_OfficeHomeAddress[
AD_7_OtherGeographicDesignation = 'OtherGeographicDesignation 2'
]/AD_0_StreetAddress
Reads as
//STF_11_OfficeHomeAddress
)[AD_7_OtherGeographicDesignation = 'OtherGeographicDesignation 2']
)/AD_0_StreetAddress
)Upvotes: 2