XML 到 JSON(Webhooks 松弛)

XML to JSON (Webhooks slack)

我想使用 xslt transformation.The 将 XML 转换为 JSON 目的是使用 Incoming Webhooks POST 进入我的松弛频道。

XML 文件:

    <?xml version="1.0" encoding="UTF-8" ?>
<Asset version="1.0">
    <Process>
        <Date>2017-01-24 14:47:35</Date>
        <Status>Success</Status
>       <Profile>TEST</Profile>
        <Station>DESKTOP</Station>
        <User>Système</User>
        <Application>APP</Application>
    </Process>
    <Source>
    </Source>
    <Target>
        <Name>Hello.mp4</Name>
    </Target>
</Asset>

我试过这个:

   <xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xsl:output method="txt" omit-xml-declaration="yes" encoding="UTF-8"/>
<xsl:template match="/">
{
"text":"<xsl:value-of select="Asset/Process/Profile"/>",
"text":"<xsl:value-of select="Asset/Process/Date"/>",
"text":"<xsl:value-of select="Asset/Target/Name"/>", 
"text":"<xsl:value-of select="Asset/Process/Status"/>", 
}
</xsl:template>
</xsl:stylesheet>

但是我遇到了这个错误:500 - missing_text_or_fallback_or_attachments

你有什么想法吗?

我需要一个像这样的 JSON :

 {     "text": "Date: 2017-01-24 14:47:35\n Status: Success\n Profile: TEST\n Station: DESKTOP\n User: Système\n Application: APP"}

https://api.slack.com/incoming-webhooks#sending_messages

这是生成所需 JSON 字符串的 XSLT:

XSLT 2.0

<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <xsl:output method="text" omit-xml-declaration="yes" encoding="UTF-8"/>
    <xsl:template match="/">
        <xsl:text>{ "text": "</xsl:text>
        <xsl:for-each select="Asset/Process/*">
            <xsl:choose>
                <xsl:when test="position()=1">
                    <xsl:value-of select="concat(local-name(),': ',.,'\n')"/>
                </xsl:when>
                <xsl:when test="position()=last()">
                    <xsl:value-of select="concat(' ',local-name(),': ',.)"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="concat(' ',local-name(),': ',.,'\n')"/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:for-each>
        <xsl:text>"}</xsl:text>
    </xsl:template>
</xsl:stylesheet>