XML重命名节点名称并将日期时间转换为日期
XML Rename node name and convert datetime to date
我有一个 xml 文件我想重命名元素名称和 return 日期的日期部分只是为了生成
<!-- reference the stylesheet -->
<?xml-stylesheet type="text/xsl" href="Dates.xsl"?>
<user>
<dob>1992-02-22T00:00:00.0000000</dob>
</user>
我想同时重命名元素名称和 return 日期的日期部分只是为了生成
<!-- reference the stylesheet -->
<?xml-stylesheet type="text/xsl" href="Dates.xsl"?>
<user>
<USER_DOB>1992-02-22</USER_DOB>
</user>
在我的 XSL 文件中
要更改元素名称,这有效
<xsl:template match="dob">
<USER_DOB><xsl:apply-templates select="node()"/></USER_DOB>
</xsl:template>
更改此作品的日期
<xsl:template match="dob">
<xsl:copy>
<xsl:call-template name="FormatDate">
<xsl:with-param name="DateTime" select="."/>
</xsl:call-template>
</xsl:copy>
</xsl:template>
<xsl:template name="FormatDate">
<xsl:param name="DateTime" />
<xsl:variable name="date">
<xsl:value-of select="substring-before($DateTime,'T')" />
</xsl:variable>
<xsl:if test="string-length($date) != 10">
<xsl:value-of select="$DateTime"/>
</xsl:if>
<xsl:if test="string-length($date) = 10">
<xsl:value-of select="$date"/>
</xsl:if>
</xsl:template>
我需要知道如何结合这两个更改来生成具有重命名节点和格式化日期的单个输出元素
谢谢,
布雷文
只需要一个匹配 dob
的模板即可...
<xsl:template match="dob">
<USER_DOB>
<xsl:call-template name="FormatDate">
<xsl:with-param name="DateTime" select="."/>
</xsl:call-template>
</USER_DOB>
</xsl:template>
我有一个 xml 文件我想重命名元素名称和 return 日期的日期部分只是为了生成
<!-- reference the stylesheet -->
<?xml-stylesheet type="text/xsl" href="Dates.xsl"?>
<user>
<dob>1992-02-22T00:00:00.0000000</dob>
</user>
我想同时重命名元素名称和 return 日期的日期部分只是为了生成
<!-- reference the stylesheet -->
<?xml-stylesheet type="text/xsl" href="Dates.xsl"?>
<user>
<USER_DOB>1992-02-22</USER_DOB>
</user>
在我的 XSL 文件中 要更改元素名称,这有效
<xsl:template match="dob">
<USER_DOB><xsl:apply-templates select="node()"/></USER_DOB>
</xsl:template>
更改此作品的日期
<xsl:template match="dob">
<xsl:copy>
<xsl:call-template name="FormatDate">
<xsl:with-param name="DateTime" select="."/>
</xsl:call-template>
</xsl:copy>
</xsl:template>
<xsl:template name="FormatDate">
<xsl:param name="DateTime" />
<xsl:variable name="date">
<xsl:value-of select="substring-before($DateTime,'T')" />
</xsl:variable>
<xsl:if test="string-length($date) != 10">
<xsl:value-of select="$DateTime"/>
</xsl:if>
<xsl:if test="string-length($date) = 10">
<xsl:value-of select="$date"/>
</xsl:if>
</xsl:template>
我需要知道如何结合这两个更改来生成具有重命名节点和格式化日期的单个输出元素 谢谢, 布雷文
只需要一个匹配 dob
的模板即可...
<xsl:template match="dob">
<USER_DOB>
<xsl:call-template name="FormatDate">
<xsl:with-param name="DateTime" select="."/>
</xsl:call-template>
</USER_DOB>
</xsl:template>