【问题标题】:Not able to copy values from two tags to another in XML using XSL无法使用 XSL 在 XML 中将值从两个标签复制到另一个标签
【发布时间】:2016-09-28 12:31:06
【问题描述】:
  1. 这是我的输入数据。它还包含许多其他字段,但我已将其删除:

    <?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 和 time 的 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>
    

我还需要做哪些更改,以便在日记帐日期标签中添加交易时间。

【问题讨论】:

    标签: xml xslt altova


    【解决方案1】:

    要将正确的值传递给您的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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-11-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-13
      • 1970-01-01
      • 2015-12-22
      相关资源
      最近更新 更多