我正在尝试根据其他一些值填充创建的日期时间。如果插入日期为空,则现在应输入,否则将显示插入日期。见下面的输入
<?xml version="1.0"?>
<a>
<x>
<id>468441</id>
<fields>
<field name="createdDateTime"/>
<field name="x">1</field>
</fields>
<b>
<queryResults>
<record id="1">
<column name="Now">2014-06-12T16:05:18+03:00</column>
<column name="InsertionDate"/>
</record>
</queryResults>
</b>
</x>
<x>
<id>468440</id>
<fields>
<field name="createdDateTime"/>
<field name="x"/>
</fields>
<b>
<queryResults>
<record id="1">
<column name="Now">2014-06-12T16:05:18+03:00</column>
<column name="InsertionDate">2015-06-12T15:25:28+03:00</column>
</record>
</queryResults>
</b>
</x>
</a>
所需的输出是
<?xml version="1.0"?>
<a>
<x>
<id>468441</id>
<fields>
<field name="createdDateTime">2014-06-12T16:05:18+03:00</field>
<field name="x">1</field>
</fields>
<b>
<queryResults>
<record id="1">
<column name="Now">2014-06-12T16:05:18+03:00</column>
<column name="InsertionDate"/>
</record>
</queryResults>
</b>
</x>
<x>
<id>468440</id>
<fields>
<field name="createdDateTime">2015-06-12T15:25:28+03:00</field>
<field name="x"/>
</fields>
<b>
<queryResults>
<record id="1">
<column name="Now">2014-06-12T16:05:18+03:00</column>
<column name="InsertionDate">2015-06-12T15:25:28+03:00</column>
</record>
</queryResults>
</b>
</x>
</a>
请参阅下面我的 xslt 1.0 代码,但它没有返回所需的输出
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
<xsl:template match="@*|node()">
<xsl:copy>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="field[@name='createdDateTime']">
<field name="createdDateTime">
<xsl:choose>
<xsl:when test="././b/queryResults/record/column[@name='InsertionDate'] ='' ">
<xsl:value-of select="././b/queryResults/record/column[@name='Now']"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="././b/queryResults/record/column[@name='InsertionDate']"/>
</xsl:otherwise>
</xsl:choose>
</field>
</xsl:template>
</xsl:stylesheet>