2016-08-18 19 views
0

xslt新手。這裏是輸入xml。無法針對特定要求創建xslt

<Response> 
    <RecordNumber/> 
    <id>2014-12-24</id> 
    <person>    
     <gender>MALE</gender> 
     <genericLocations>    
      <effective>2012-11-28</effective> 
     </genericLocations> 
     <genericLocations>    
      <expiration>2012-11-27</expiration>    
      <effective>2008-12-09</effective> 
     </genericLocations> 
     <genericLocations> 
      <expiration>2008-12-08</expiration>    
      <effective>2006-01-13</effective> 
     </genericLocations> 
     <genericLocations> 
      <expiration>2006-01-12</expiration>    
      <effective>2001-07-17</effective> 
     </genericLocations> 
     <genericLocations>    
      <expiration>2001-07-16</expiration>    
      <effective>1901-01-01</effective> 
     </genericLocations> 
     </person> 
    </Response> 

這裏是所需的輸出XML:

<Response> 
    <RecordNumber/> 
    <id>2014-12-24</id> 
    <person>    
     <gender>MALE</gender> 
     <genericLocations>    
      <effective>2012-11-28</effective> 
     </genericLocations>    
     </person> 
    </Response> 

輸出XML需要包含僅一個「genericLocations」節點在其中的「到期」可以是空的(或缺失)或「過期」是在未來(大於今天的日期)。

任何幫助,非常感謝。

+0

相關:http://stackoverflow.com/questions/20342805/xslt-1-0-compare-dates –

+0

** 1。**請註明是否使用XSLT 1.0或2.0。如果XSLT 1.0,哪個特定的處理器? ** 2。**如果有多個節點符合標準,該怎麼辦?如果沒有? –

回答

0

假設XSLT 2.0,你想

<xsl:template match="person"> 
    <xsl:copy-of select="gender, 
    genericLocations[not(xs:date(expiration) le current-date())][1]"/> 
</xsl:template> 

加上身份模板複製其他一切不變。