2014-10-30 75 views
1

從以下xml文件中,我想根據一個條件從biilingbatch中刪除「centrum」標籤。條件是如果是1921年,那麼我想從XML中刪除椎體標記。在xml中,在不同的Parent標籤下有許多中心標籤。我想刪除那個中心標籤whoes父標籤是billingbatch。 我的XML是:我想根據條件使用XSLT刪除xml標籤

<calculate> 
     <calculateAmount> 
      <currency>978</currency> 
      <individualAmount>-10000</individualAmount> 
      <billingType>1</billingType> 
      <billingPeriodEndDate>20260214</billingPeriodEndDate> 
      <extMvmtFinInstMode>8</extMvmtFinInstMode> 
     <billingbatch> 
         <Account>1921</Account> 
         <Centrum>LBNG</Centrum> 
         <Company>LNS</Company> 
         <TextCode>570</TextCode> 
         <TextData>952491</TextData> 
     </billingbatch> 

     <calculatebillingbatch> 
       <Account>1921</Account> 
         <Centrum>LBNG</Centrum> 
         <Company>LNS</Company> 
         <TextCode>570</TextCode> 
         <TextData>952491</TextData> 
     </calculatebillingbatch> 
     </calculateAmount> 

預期的結果是:

<calculate> 
     <calculateAmount> 
      <currency>978</currency> 
      <individualAmount>-10000</individualAmount> 
      <billingType>1</billingType> 
      <billingPeriodEndDate>20260214</billingPeriodEndDate> 
      <extMvmtFinInstMode>8</extMvmtFinInstMode> 
     <billingbatch> 
         <Account>1921</Account>        
         <Company>LNS</Company> 
         <TextCode>570</TextCode> 
         <TextData>952491</TextData> 
     </billingbatch> 

     <calculatebillingbatch> 
       <Account>1921</Account> 
         <Centrum>LBNG</Centrum> 
         <Company>LNS</Company> 
         <TextCode>570</TextCode> 
         <TextData>952491</TextData> 
     </calculatebillingbatch> 
     </calculateAmount> 

+0

看看這個:http://www.youtube.com/watch?v=hzGG32kz9nc – 2014-10-30 07:29:05

回答

0

好使用身份轉換模板

<xsl:template match="@* | node()"> 
    <xsl:copy> 
    <xsl:apply-templates select="@*| node()"/> 
    </xsl:copy> 
</xsl:template> 

和templa TE

<xsl:template match="billingbatch[Account = 1921]/Centrum"/> 
+0

如果我要刪除「中樞」標籤有兩個帳戶沒有。像1921年和5740我不想要「中心」標籤那麼最新的代碼中的變化? – Neel 2014-10-30 09:39:10

+0

使用帶'或'條件的謂詞:''。 – 2014-10-30 09:43:59