无法使用XSL将值从两个标记复制到另一个XML

问题描述:

  1. 这是我的输入数据。它包含了许多其他领域也有,但是我已经删除它们:无法使用XSL将值从两个标记复制到另一个XML

    <?xml version="1.0" encoding="UTF-8"?> 
    <tables> 
    <table> 
        <row> 
        <JOURNAL_DATE></JOURNAL_DATE> 
        <TRANSACTION_DATE>2016-08-15T00:00:00-04:00</TRANSACTION_DATE> 
        <TRANSACTION_TIME>11:52:18.005</TRANSACTION_TIME> 
        </row> 
    <table> 
    </tables> 
    
  2. 我想这样的输出,其中journal_date是TRANSACTION_DATE具有日期值和transaction_time时间:

    <JOURNAL_DATE>2016-08-15 11:52:18.005</JOURNAL_DATE> 
    <TRANSACTION_DATE>2016-08-15T00:00:00-04:00</TRANSACTION_DATE> 
    <TRANSACTION_TIME>11:52:18.005</TRANSACTION_TIME> 
    
  3. 我正在使用以下XSL代码,需要做哪些更改?我是一个新手。

    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> 
    <xsl:output method="xml" encoding="UTF-8" indent="yes" omit-xml-declaration="yes" /> 
    <xsl:template match="node()|@*"> 
    <xsl:copy> 
        <xsl:apply-templates select="node()|@*"/> 
    </xsl:copy> 
    </xsl:template> 
    <!--Suryanshu For adding required date format --> 
    
    <xsl:template match="JOURNAL_DATE"> 
    <xsl:copy> 
        <xsl:call-template name="formatdate"> 
        <xsl:with-param name="datestr" select="."/> 
        </xsl:call-template> 
    </xsl:copy> 
    </xsl:template> 
    
    
    <xsl:template name="formatdate"> 
    <xsl:param name="datestr"/> 
    <xsl:value-of select="substring($datestr,1,10)"/> 
    </xsl:template> 
    
    </xsl:stylesheet> 
    

更重要的是改变做我需要做的,这样交易时间在日志日期标签添加。

正确的值传递到您的formatdate模板,你需要引用交易日是这样的...

<xsl:with-param name="datestr" select="../TRANSACTION_DATE"/> 

其中,..选择父元素row

试试这个XSLT模板

<xsl:template match="JOURNAL_DATE"> 
<xsl:copy> 
    <xsl:call-template name="formatdate"> 
    <xsl:with-param name="datestr" select="../TRANSACTION_DATE"/> 
    </xsl:call-template> 
    <xsl:text> </xsl:text> 
    <xsl:value-of select="../TRANSACTION_TIME" /> 
</xsl:copy> 
</xsl:template>