xml - 如何在 if 条件下分配固定值
问题描述
我正在使用 XSL 样式表转换几个 XML。
但是,在某些情况下,“日期”字段只有年份而不是完整日期 DD/MM/YYYY。
这里举个例子。
<?xml version="1.0" encoding="UTF-8"?>
<objects>
<oeu>
<oeu_archive_exist_construct_timespan type="daterange">
<from>1999</from>
<to>2001</to>
</oeu_archive_exist_construct_timespan>
</oeu>
</objects>
通过应用以下 XSL:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml"
indent="yes"
encoding="UTF-8"/>
<xsl:template match="/">
<root>
<xsl:apply-templates/>
</root>
</xsl:template>
<xsl:template match="@*|node()"
mode="copy-no-namespaces">
<xsl:copy>
<xsl:apply-templates select="@*|node()"
mode="copy-no-namespaces"/>
</xsl:copy>
</xsl:template>
<xsl:template match="pr:objects/pr:oeu">
<entry>
<xsl:element name="construction_time_span">
<oeu_nc_construction_time_span_from>
<xsl:value-of select="pr:oeu_archive_exist_construct_timespan/pr:from"/>
</oeu_nc_construction_time_span_from>
<oeu_nc_construction_time_span_to>
<xsl:value-of select="pr:oeu_archive_exist_construct_timespan/pr:to"/>
</oeu_nc_construction_time_span_to>
</xsl:element>
</entry>
</xsl:template>
</xsl:stylesheet>
我有以下输出(快照):
<construction_time_span>
<oeu_nc_construction_time_span_from>1999</oeu_nc_construction_time_span_from>
<oeu_nc_construction_time_span_to>2001</oeu_nc_construction_time_span_to>
</construction_time_span>
在日期只有年份的情况下,我想将固定值 1/1 分配为 DD/MM。
我想要的输出是:
<construction_time_span>
<oeu_nc_construction_time_span_from>1/1/1999</oeu_nc_construction_time_span_from>
<oeu_nc_construction_time_span_to>1/1/2001</oeu_nc_construction_time_span_to>
</construction_time_span>
建议?
问候,
解决方案
推荐阅读
- java - Jackson 对象映射器 com.fasterxml.jackson.databind.exc.MismatchedInputException
- excel - 根据发送的具有相同主题的不同邮件获取投票响应
- junit - 列表的 Hamcrest 匹配器
> - amazon-web-services - AWS CloudTrail 查找事件 API
- java - Java API - Pentaho - PDI - 转换路径...无效,不会成功运行
- angular - 如何为从 Angular 中的 API 后端收集的提供者设置值
- python - 如何用 conda 安装考拉?
- nfc - 如何在 Mifare Desfire EV2 NFC 徽章上编写应用程序
- angular - 在 angular jasmine karma 测试中触发 dragstart 事件
- flutter - Flutter - FutureBuilder - 搜索