2009-08-06 46 views
0

嗨我遇到的XML文件:日期時間在XSLT

<order><Extension Properties><Date>2009-08-04T17:09:04.593+05:30</Date></Extension Properties></Order> 

,我想輸出作爲

生成日期040809

我想通過xslt.Please幫助做到這一點.. !!

回答

0

使用this爲指導...

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:template match="/"> 
    <order> 
     <xsl:element name="GenerationDate"> 
     <xsl:call-template name="FormatDate"> 
      <xsl:with-param name="DateTime" select="order/Extension/Date"/> 
     </xsl:call-template> 
     </xsl:element> 
    </order> 
    </xsl:template> 

    <xsl:template name="FormatDate"> 
    <xsl:param name="DateTime" /> 
    <xsl:variable name="day"> 
     <xsl:value-of select="substring($DateTime,9,2)" /> 
    </xsl:variable> 
    <xsl:variable name="month"> 
     <xsl:value-of select="substring($DateTime,6,2)" /> 
    </xsl:variable> 
    <xsl:variable name="year"> 
     <xsl:value-of select="substring($DateTime,3,2)" /> 
    </xsl:variable> 
    <xsl:value-of select="$day"/> 
    <xsl:value-of select="$month"/> 
    <xsl:value-of select="$year"/> 
    </xsl:template> 
</xsl:stylesheet> 
+0

我不認爲''會起作用。元素名稱中的空格是非法的。 ;-) – Tomalak 2009-08-06 13:44:18

+0

@Tomalak - 很好,我還在通過第一杯咖啡。 :) – MyItchyChin 2009-08-06 14:14:25

0
<xsl:variable name="dateString" select="order/Extension/Date/> (or something along those lines) 

<xsl:value-of select="substring($date,9,10)"><xsl:value-of select="substring($date,6,7)"><xsl:value-of select="substring($date,1,4)"> 
0

檢查this文章。我想你可以使用日期函數在XSLT標準庫

1

一種方法是使用子功能:

<xsl:variable name="d" select="/order/Extension/Date" /> 
Generation Date <xsl:value-of select="concat(
substring($d, 9, 2), 
substring($d, 6, 2), 
substring($d, 3, 2))"/> 

其他答案可能取決於你所使用的XSL引擎。例如,如果您使用的是MSXML,則可以使用日期時間擴展功能:

<?xml version="1.0" encoding="utf-8"?> 
<xsl:stylesheet version="1.0" 
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:ms="urn:schemas-microsoft-com:xslt"> 
    <xsl:output method="xml" /> 

    <xsl:template match="/"> 

     <xsl:template match="Date"> 
     <xsl:variable name="d" select="/order/Extension/Date" /> 
     Generation Date 
     <xsl:value-of select="ms:format-date($d, 'ddMMyy')"/> 

    </xsl:template> 

</xsl:stylesheet> 

祝您好運!