【发布时间】:2021-01-24 06:58:59
【问题描述】:
我是 xslt 的新手。
我正在尝试使用 xslt 将 json 转换为 csv。
这是输入的json
[
{
"id": "1",
"name": "manu"
},
{
"id": "2",
"name": "vivek"
}
]
而 XSLT 是:-
我很确定我没有在 select 属性中进行正确的映射。
谁能帮我解决这个问题
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
extension-element-prefixes="math"
xmlns:math="http://exslt.org/math"
xmlns:xs="http://www.w3.org/2001/XMLSchema" version="3.0" xmlns="http://www.w3.org/2005/xpath-functions" xpath-default-namespace="http://www.w3.org/2005/xpath-functions" expand-text="yes" >
<xsl:param name="input"/>
<xsl:output method="text"/>
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<xsl:template name="initial-template">
<xsl:variable name="input-as-xml" select="json-to-xml($input)"/>
<xsl:for-each select="$input-as-xml//*">
<xsl:variable name="eachData" select="."></xsl:variable>
<xsl:choose>
<xsl:when test="contains($eachData,',')">
<xsl:value-of select="replace($eachData, ',', ' ')"/>
</xsl:when>
<xsl:otherwise>
<xsl:value-of select="$eachData"/>
</xsl:otherwise>
</xsl:choose>
<xsl:if test="position() != last()">
<xsl:value-of select="','"/>
</xsl:if>
</xsl:for-each>
<xsl:text> </xsl:text>
</xsl:template>
</xsl:stylesheet>
【问题讨论】: