2012-03-26 101 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