我正在对从FlatFile生成的一些输入XML执行XSLT转换。我想将元素的数据类型更改为“date”,但不在输出XML中显示它。
输入XML:
<PostingDate>20141009</PostingDate>
XSLT转型:
<cdm:PostingDate>
<xsl:attribute name="name">
<xsl:value-of select="PostingDate"/>
</xsl:attribute>
<xsl:attribute name="type">xs:decimal</xsl:attribute>
</cdm:PostingDate>
当前输出:
<cdm:PostingDate name="20141009" type="xs:decimal"/>
必填项:
<cdm:PostingDate>2014-10-09</cdm:PostingDate>
注意: 类似地,我想做一些其他转换,比如将一些XML元素转换为十进制和字符串。是否可以在XSLT 2.0中使用?
答案 0 :(得分:2)
我想将元素的数据类型更改为“date”但没有 在输出xml中显示它。
这是一个毫无意义的愿望,因为输出不带有数据类型,并且在处理过程中你不需要数据类型(至少我没有看到你这样做)。你为什么不这样做:
<cdm:PostingDate>
<xsl:value-of select="concat(substring(PostingDate, 1, 4), '-', substring(PostingDate, 5, 2), '-', substring(PostingDate, 7, 2))"/>
</cdm:PostingDate>
我想说的是它是某种管道。
AFAIK,如果你这样做:
<cdm:PostingDate>
<xsl:sequence select="xs:date(concat(substring(PostingDate, 1, 4), '-', substring(PostingDate, 5, 2), '-', substring(PostingDate, 7, 2)))"/>
</cdm:PostingDate>
然后<cdm:PostingDate>
的数据类型将保持xs:date
,直到输出序列化为止。