简体   繁体   English

XSLT 2.0中的数据类型转换

[英]Datatype Conversion in XSLT 2.0

I am performing XSLT transformation on some input XML which is generated from a FlatFile. 我正在对从FlatFile生成的某些输入XML执行XSLT转换。 I want to change the datatype of a element to "date" but without showing it in output XML. 我想将元素的数据类型更改为“日期”,但不将其显示在输出XML中。

Input XML: 输入XML:

<PostingDate>20141009</PostingDate>

XSLT Transformation: XSLT转换:

<cdm:PostingDate>
    <xsl:attribute name="name"> 
       <xsl:value-of select="PostingDate"/>
    </xsl:attribute>
    <xsl:attribute name="type">xs:decimal</xsl:attribute>
</cdm:PostingDate>

Current Output: 电流输出:

<cdm:PostingDate name="20141009" type="xs:decimal"/>

Required Output: 要求的输出:

<cdm:PostingDate>2014-10-09</cdm:PostingDate>

Note: Similarly I want to do some other transformations like to convert some XML elements into decimal and strings. 注意:同样,我想进行其他一些转换,例如将一些XML元素转换为十进制和字符串。 Is it possible in XSLT 2.0? XSLT 2.0中可能吗?

I want to change the data type of a element to "date" but without showing it in output xml. 我想将元素的数据类型更改为“日期”,但不将其显示在输出xml中。

That's a rather meaningless wish, since the output does not carry the data type with it, and you don't need the data type during the processing (at least I don't see that you do). 这是一个毫无意义的愿望,因为输出不带有数据类型,并且在处理过程中不需要数据类型(至少我看不到)。 Why don't you do simply: 为什么不简单地做:

<cdm:PostingDate>
    <xsl:value-of select="concat(substring(PostingDate, 1, 4), '-', substring(PostingDate, 5, 2), '-', substring(PostingDate, 7, 2))"/>
</cdm:PostingDate>

Edit: 编辑:

what i meant to say was that it is a some sort of pipe. 我的意思是说这是某种管道。

AFAIK, if you do: AFAIK,如果您这样做:

<cdm:PostingDate>
    <xsl:sequence select="xs:date(concat(substring(PostingDate, 1, 4), '-', substring(PostingDate, 5, 2), '-', substring(PostingDate, 7, 2)))"/>
</cdm:PostingDate>

then the data type of <cdm:PostingDate> will remain xs:date until the output is serialized. 然后<cdm:PostingDate>的数据类型将保持xs:date直到输出被序列化。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM