2012-03-26 102 views
0

如果找到節點中的某個值,我想知道是否可以用XLST選擇一個值。我對XSLT沒有任何經驗,但我需要這個在Microsoft BizTalk中的過程。XSLT如果節點中存在值,則選擇該值

所以我想去做的例子:

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

如果價值<AD_7_OtherGeographicDesignation>OtherGeographicDesignation 2</AD_7_OtherGeographicDesignation>存在,選擇<AD_0_StreetAddress>Street 2</AD_0_StreetAddress>。唯一的問題是,序列並不總是相同的,並且節點<STF_11_OfficeHomeAddress>可以在同一個文件中出現11次。

有人可以幫我嗎?

回答

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

讀作

  • 任何辦公室/家庭地址的...(//STF_11_OfficeHomeAddress
  • ...有其其他地理標誌在一定的價值... ([AD_7_OtherGeographicDesignation = 'OtherGeographicDesignation 2']
  • ...選擇街道地址。 (/AD_0_StreetAddress
+0

非常感謝你! – user1292411 2012-03-26 08:07:29

1

經過至少Jeni Tennison's XSLT tutorial pages第一基本部分,然後您就能夠通過做俯臥撐模式(而不是拉模式),並使用謂詞與你匹配的規則,如本做自己:

<xsl:template match="AD_0_StreetAddress[../AD_7_OtherGeographicDesignation]"> 
    <xsl:value-of select="."/> 
+0

+1,但OP的匹配表達仍然會有所不同。 – Tomalak 2012-03-26 08:04:21

+0

謝謝你的教程頁面,我會檢查出來... – user1292411 2012-03-26 08:07:59