我有一个请求 xml,其中有一个 json -> 我想使用 xslt 将其映射到另一个 json。我正在使用 xslt 1.0。有没有办法在 xslt 1.0 中实现这一点: 请求xml是:
<root> { id: 5656, country-name: 'country-text' } <root>
我需要映射到的响应:
{ mid: 5656, cid : 'country-text' }
请帮忙
我尝试了一些方法,能够将源 json 复制到最终响应中 - 但这没有帮助,因为我需要读取各个字段并将它们映射到不同的键
用我尝试过的方法 -> 我能够得到
{id:5656, country-name:'country-text' }
我想要的是:
{ mid: 5656, cid : 'country-text' }
我想这是你看待它的一种方式:
XSLT 1.0
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" encoding="UTF-8"/>
<xsl:template match="/root">
<xsl:text>{ mid: </xsl:text>
<xsl:value-of select="substring-before(substring-after(., 'id: '), ',')" />
<xsl:text>, cid : </xsl:text>
<xsl:value-of select="substring-before(substring-after(., 'country-name: '), ' }')" />
<xsl:text> }</xsl:text>
</xsl:template>
</xsl:stylesheet>