XSLT选择值if节点中的值是否存在

时间:2012-03-26 07:47:31

标签: xml xslt biztalk biztalk-2010

我想知道如果找到节点中的值,是否可以使用XLST选择值。我没有使用XSLT的经验,但我需要这个用于Microsoft BizTalk中的进程。

这是我想做的一个例子:

<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 个答案:

答案 0 :(得分:2)

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

读为

  • 任何办公室/家庭住址 ...(//STF_11_OfficeHomeAddress
  • ... 其他地理名称处于特定值...([AD_7_OtherGeographicDesignation = 'OtherGeographicDesignation 2']
  • ...选择街道地址。 (/AD_0_StreetAddress

答案 1 :(得分:1)

首先至少浏览Jeni Tennison's XSLT tutorial pages的基本部分,然后您可以通过执行推送模式(而不是拉模式)并使用带有匹配规则的谓词来自行完成此操作,例如: / p>

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