2013-01-07 25 views
1

我試圖產生從XML文件,其包括「OtherEmployees」與出生日期的計數的日期之前的.csv(例如01/01/1970),我不確定語法。XSLT計數元件

注意,日期目前在DD/MM/yyyy格式。

這是XML的例子 -

<Companies> 
<Company> 
    <CompanyReference>00000060</CompanyReference> 
    <Contact> 
     <PersonID>63</PersonID> 
     <Title>Mrs</Title> 
     <Forename>EXAMPLE</Forename> 
     <Middlename/> 
     <Surname>NAME</Surname> 
     <DOB>27/05/1928</DOB> 
    </Contact> 
    <OtherEmployees> 
     <OtherEmployee> 
      <PersonID>28870</PersonID> 
      <Title>Miss</Title> 
      <Forename>EXAMPLE</Forename> 
      <Middlename/> 
      <Surname>NAME2</Surname> 
      <DOB>03/05/1953</DOB> 
     </OtherEmployee> 
     <OtherEmployee> 
      <PersonID>28871</PersonID> 
      <Title>Miss</Title> 
      <Forename>EXAMPLE</Forename> 
      <Middlename/> 
      <Surname>NAME3</Surname> 
      <DOB>11/07/1961</DOB> 
     </OtherEmployee> 
    </OtherEmployees> 
</Company> 

我能夠儘可能獲得儘可能OtherEmployees的計數出生的帶有日期如下 -

<xsl:value-of select="count(OtherEmployees/OtherEmployee[DOB])"/> 

但是我現在需要的DOB與其他日期比較 - 比如01/01/1970並且只返回OtherEmployee在計數,如果他們01/01/1970之前有出生日期。

回答

2

隨着XSLT 2.0你可以使用的xs:日期數據類型例如

<xsl:value-of select="count(OtherEmployees/OtherEmployee[DOB and xs:date(concat(substring(DOB, 7), '-', substring(DOB, 4, 2), '-', substring(DOB, 1, 2))) lt xs:date('1970-01-01')])"/> 

使用XSLT 1.0您可以將您的數據格式dd/mm/yyyy容易轉換爲數字yyyymmdd和比較上:

<xsl:value-of select="count(OtherEmployees/OtherEmployee[DOB and number(concat(substring(DOB, 7), substring(DOB, 4, 2), substring(DOB, 1, 2))) &lt; 19700101])"/> 
+0

那沒有我需要什麼。然而有一個右括號失蹤子串之後(DOB,1,2))。非常感謝。 – user1955411

+1

我糾正語法錯誤,我們對此深感抱歉,沒有一個代碼編輯器或編譯器也很難抓到這些類型的錯誤。如果答案解決了你的問題,你可以接受它。 –