2015-03-02 81 views
0

如果Address元素的type屬性=「Standard With Attention」,我不想顯示AddressLine1。相反,我只想顯示AddressLine2,AddressLine3和AddressLine4。 我的輸出如果元素屬性有注意,我想省略addressLine1

經辦人:邁克爾,134 w ^百老匯ST NW,APT 3B,華盛頓特區,12345

預期輸出: 134W¯¯百老匯ST NW,APT 3B,華盛頓特區12345

我的XML

<ProtectedAddresses> 
    <Address InternalAddressID="1618613567" Type="Standard With Attention"> 
     <AddressLine1>Attn: Michael</AddressLine1> 
     <AddressLine2>134 W Broadway ST NW</AddressLine2> 
     <AddressLine3>APT 3B</AddressLine3> 
     <AddressLine4>Washington, DC, 12345</AddressLine4> 
     <Attention>James</Attention> 
     </Address> 
</ProtectedAddresses> 

XSLT

<xsl:for-each select="Addresses/Address"> 
    <xsl:for-each select="ancestor::ProtectionOrder/ProtectionOrderParties/ProtectionOrderParty/DCProtectionOrderPartyAdditional/ProtectedAddresses/Address[@InternalAddressID=current()/@InternalAddressID]"> 
    <xsl:for-each select="AddressLine1 | AddressLine2 | AddressLine3 | AddressLine4"> 
     <xsl:value-of select="."/> 
     <xsl:if test="position()!=last()">, </xsl:if> 
    </xsl:for-each> 
    <xsl:text>; </xsl:text> 
    </xsl:for-each> 
</xsl:for-each> 

回答

0

如果您要更換<xsl:for-each select="AddressLine1 | AddressLine2 | AddressLine3 | AddressLine4"><xsl:for-each select="AddressLine1[not(../@Type = 'Standard With Attention')] | AddressLine2 | AddressLine3 | AddressLine4">在構造節點設定如果條件../@Type = 'Standard With Attention'是真實的,只有三個要素。

+0

令人敬畏的把條件放在AddressLine1上工作 – Angela 2015-03-02 19:21:36

0

你的例子相當混亂,因爲你只向我們展示了一部分XML。因此,很難給出準確的答案,因爲背景不夠清楚,而且不可能根據您的輸入測試給定的答案。

恕我直言,你應該使用關鍵,而不是這樣的:

<xsl:for-each select="ancestor::ProtectionOrder/ProtectionOrderParties/ProtectionOrderParty/DCProtectionOrderPartyAdditional/ProtectedAddresses/Address[@InternalAddressID=current()/@InternalAddressID]"> 

現在,爲了解決您的問題(儘可能地):排除AddressLine1在某些情況下,你應該追加它一個謂語 - 即是這樣的:

<xsl:for-each select="AddressLine1[not(../@Type='Standard With Attention')] | AddressLine2 | AddressLine3 | AddressLine4"> 

這將工作,如果 - 因爲它似乎 - 條件在實際012的父元素存在。

+0

感謝您的幫助。這工作正如我使用Martin Honnen提供的相同代碼。我不確定如何使用密鑰,而不是使用我的代碼'> – Angela 2015-03-02 19:22:46

+0

@Angela我建議你發佈一個關於這個問題的另一個問題,用一個最小但完整的XML例子。 – 2015-03-02 20:29:58

相關問題