我需要将单独的日期和时间合并为一种针对XSLT的日期时间格式。我是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>
答案 0 :(得分:3)
使用以下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>