JSON to XML SXLT



目前,我尝试将Rocket Chat(RC(webhook的json响应映射到OTRS XSLT。

  1. 以下是我从RC收到的信息

{
"_id":"4jA2dgTGzwsHSsiLd",
"messages":[
{ 
"username":"guest-3",
"msg":"youuu",
"ts":"2018-12-13T15:13:56.906Z", 
},
{
"username":"agent",
"msg":"hahahaha",
"ts":"2018-12-13T15:14:06.268Z"
},
{
"username":"agent",
"msg":"mane tn?",
"ts":"2018-12-13T15:14:08.817Z"
},
]
}

  1. 及以下是我当前的OTRS XSLT映射

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:variable name="title">
<xsl:value-of select="//type" />
</xsl:variable>

<xsl:variable name="custname">
<xsl:value-of select="//visitor/name" />
</xsl:variable>

<xsl:variable name="custemail">
<xsl:value-of select="//visitor/email/address" />
</xsl:variable>

<xsl:variable name="tn">
<xsl:value-of select="//tags" />
</xsl:variable>
<xsl:variable name="createtime">
<xsl:value-of select="//createdAt" />
</xsl:variable>

<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*" />
</xsl:copy>
</xsl:template>
<xsl:template match="RootElement">
<xsl:copy>
<TicketNumber><xsl:value-of select="$tn" /></TicketNumber>
<Article>
<Body> ? </Body>
<ContentType>text/html; charset=ISO-8859-15</ContentType>
<Subject><xsl:value-of select="$title" /></Subject>
<From><xsl:value-of select="$custemail" /></From>
<ArticleType>webrequest</ArticleType>
<SenderType>customer</SenderType>
<To>Misc</To>
<HistoryType>AddNote</HistoryType>
<HistoryComment>Note from RC</HistoryComment>
</Article>
<xsl:apply-templates select="@*|node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="content" />
</xsl:stylesheet>

我想从JSON中获取messages->username和messages->msg的所有值,并将其传递给Body标记。也许像:

短信:你好世界发件人:guest3

Msg:你好由:代理

或者html表?

提前感谢。

想明白了。。这应该放在标签中

<xsl:for-each select="//messages">
<xsl:value-of select="msg" />
&lt;br/&gt;
<xsl:value-of select="username" />
&lt;br/&gt;
&lt;br/&gt;
<xsl:if test="./following-sibling::cd">,</xsl:if>
</xsl:for-each>

最新更新