[英]OSB transform String to DateTime (xsl or xquery)
I'm working with Oracle OSB and I have the following incoming xml message:我正在使用 Oracle OSB,收到以下传入的 xml 消息:
<db:InputParameters>
<db:DETAILS>
<db:DETAILS_ITEM>
<db:Mutate>W</db:Mutate>
<db:Date>2020-04-06T14:43</db:Date>
<db:Account>T</db:Account>
</db:DETAILS_ITEM>
<db:DETAILS_ITEM>
<db:Mutate>W</db:Mutate>
<db:Date>2020-04-06T14:43</db:Date>
<db:Account>T</db:Account>
</db:DETAILS_ITEM>
</db:DETAILS>
</db:InputParameters>
The element "Date" is a "string" -> according to the xsd. But the application that I'm sending this message to, expects a "DateTime" type.根据 xsd,元素“Date”是一个“字符串”->。但是我要将此消息发送到的应用程序需要一个“DateTime”类型。 So I need to transform the element "Date" from type "String" to type "DateTime".
所以我需要将元素“Date”从类型“String”转换为类型“DateTime”。 Keep in mind that the incoming message has more than one element called "Date".
请记住,传入的消息具有不止一个称为“日期”的元素。 I tried a For Each stage with a replace action but I couldn't get it to work.
我尝试了一个带有替换操作的 For Each 阶段,但我无法让它工作。
Also, I tried to concat ":00" to the "Date" element with the expression: fn:concat($body/*:inputparameters/*:DETAILS/*:DETAILS_ITEM/*:Date,':00')
This didn't seem to work either.此外,我尝试使用以下表达式将“:00”连接到“日期”元素:
fn:concat($body/*:inputparameters/*:DETAILS/*:DETAILS_ITEM/*:Date,':00')
这没有' 似乎工作。
What would be the most simple solution to this?对此最简单的解决方案是什么?
Thanks for the help.谢谢您的帮助。
With XSLT you can change the value of the element as follows:使用 XSLT,您可以按如下方式更改元素的值:
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:db="http://example.com/db"
version="1.0">
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="db:DETAILS_ITEM/db:Date">
<xsl:copy>
<xsl:value-of select="concat(., ':00')"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
https://xsltfiddle.liberty-development.net/pNmCzsv https://xsltfiddle.liberty-development.net/pNmCzsv
Note that this is simply changing the contents of that element to a value which can be parsed as an xs:dateTime
.请注意,这只是将该元素的内容更改为可以解析为
xs:dateTime
的值。 There is no schema involved or any validation done.不涉及模式或完成任何验证。 You will need to adapt the namespace declaration
xmlns:db="http://example.com/db"
to the one of the input document.您需要将命名空间声明
xmlns:db="http://example.com/db"
调整为输入文档之一。
With some help from a colleague I found the following solution.在同事的帮助下,我找到了以下解决方案。
In the first pipeline that picks up the incoming message from the queue, I added a "For-each stage" with a "replace stage" inside that looks like this:在从队列中获取传入消息的第一个管道中,我添加了一个“For-each stage”,里面有一个“replace stage”,如下所示:
For Each [ curValue ] in [*:InputParameters/*:DETAILS/*:DETAILS_ITEM/*:Date]
of [ body ]
Indexed by [ curIndex ] with total count in [ curCount ]
Do (
Replace [ node contents ] of [ *:InputParameters/*:DETAILS/*:DETAILS_ITEM[$curIndex]/*:Date]
in [ body ] with [ fn:concat($curValue,":00")]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.