2014-11-25 57 views
1

我需要將單獨的日期和時間合併爲一個針對XSLT的日期時間格式。我非常喜歡XSLT。我一直在Google上搜索並盡力而爲。我找不到解決方案。希望你能幫助我。謝謝!如何將單獨的日期和時間變量合併爲一個日期時間格式XSLT

原始XML文件:

<ns0:TransactionRequests xmlns:ns0="http://tst.co.za/sa/co/cib/servicesV1"> 
    <CorporatePayments> 
     <TransactionDate>20140926</TransactionDate> 
     <TransactionTime>001502</TransactionTime> 
    </CorporatePayments> 
</ns0:TransactionRequests> 

XSLT:

<xsl:template match="CorporatePayments" > 
    <Transactions> 
    <Transaction bankDate="{TransactionDate+TransactionTime}"> 
    </Transaction> 
    <Transactions> 
</xsl:template> 

以XML格式預期結果:

<Transactions> 
    <Transactions> 
    <Transaction bankDate="2014-09-26T00:15:02" /> 
</Transactions> 
</Transactions> 

回答

3

使用FO正在使用XSLT:

<?xml version="1.0" encoding="UTF-8"?> 
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://tst.co.za/sa/co/cib/servicesV1" exclude-result-prefixes="ns0"> 
<xsl:output indent="yes" method="xml" omit-xml-declaration="yes" /> 
<xsl:strip-space elements="*"/> 
<xsl:template match="/ns0:TransactionRequests/CorporatePayments" > 
    <Transactions> 
     <Transactions> 
      <xsl:variable name="D" select='TransactionDate'/> 
      <xsl:variable name="T" select='TransactionTime'/> 
      <Transactions bankDate="{concat(substring($D,1,4), '-',substring($D,5,2),'-',substring($D,7,2),'T',substring($T,1,2),':',substring($T,3,2),':',substring($T,5,2))}"/> 
     </Transactions> 
    </Transactions> 
</xsl:template> 
</xsl:stylesheet> 
相關問題