XSLT 2.0中的数据类型转换

时间:2014-11-11 04:42:58

标签: xml xslt xslt-2.0

我正在对从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中使用?

1 个答案:

答案 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,直到输出序列化为止。