XSLT 1.0:使用 XSLT 格式化 JSON 输出/删除 JSON 数组中的默认引号

XSLT 1.0: Format JSON output using XSLT/ Remove defualt quotes in an JSON Array

我有以下 JSON 响应,这是我在 XSLT 转换后得到的。 "name" 数组中的值需要显示为 "ABC","XYZ"

有效载荷

<Data>
 <Mapping>
   <LocationID>001</LocationID>
   <GeoX>1.00</GeoX>
   <GeoY>2.00</GeoY>
 </Mapping>
 <Mapping>
   <LocationID>002</LocationID>
   <GeoX>56.00</GeoX>
   <GeoY>42.00</GeoY>
 <Mapping>
</Data>

实现 Destination 对象的当前代码。

<xsl:template match="//Data">
   <Destination>
      <Locations>
          <xsl:text disable-output-escaping="yes">&lt;?xml-multiple?&gt;</xsl:text>
            <Name>
             <jsonArray>
               <xsl:for-each select="Mapping">
                  <xsl:choose>
                     <xsl:when test="LocationID='001'">"ABC"</xsl:when>
                     <xsl:when test="LocationID='002'">"XYZ"</xsl:when>
                     <xsl:otherwise>"NEW"</xsl:otherwise>
                  </xsl:choose>
                  <xsl:if test="position()!=last()">,</xsl:if>
               </xsl:for-each>
              </jsonArray>
            </Name>
        </Locations>
    </Destination>
</xsl:template>

XML输出

<Destination>
  <Locations>
    <Name>"ABC","XYZ"</Name>
  </Locations>
</Destination>

问题XML-到-JSON输出

"Destination": [
    {
        "Locations": {
            "Name": [
                "\"ABC\",\"XYZ\""
            ]
        },

预期JSON输出

"Destination": [
    {
        "Locations": {
            "Name": [
                "ABC","XYZ"
            ]
        },

这个“\"ABC\",\"XYZ\"”转义字符在我将 XML 转换为 JSON 时发生。有没有办法克服这个问题。

我可以通过如下更改上面的代码来解决这个问题。

前一码:

<xsl:template match="//Data">
   <Destination>
      <Locations>
          <xsl:text disable-output-escaping="yes">&lt;?xml-multiple?&gt;</xsl:text>
            <Name>
             <jsonArray>
               <xsl:for-each select="Mapping">
                  <xsl:choose>
                     <xsl:when test="LocationID='001'">"ABC"</xsl:when>
                     <xsl:when test="LocationID='002'">"XYZ"</xsl:when>
                     <xsl:otherwise>"NEW"</xsl:otherwise>
                  </xsl:choose>
               </xsl:for-each>
              </jsonArray>
            </Name>
        </Locations>
    </Destination>
</xsl:template>

更改代码:

<xsl:template match="//Data">
   <Destination>
      <Locations>
               <xsl:for-each select="Mapping">
                  <xsl:choose>
                     <xsl:when test="LocationID='001'"><Name>ABC</Name></xsl:when>
                     <xsl:when test="LocationID='002'"><Name>XYZ</Name></xsl:when>
                     <xsl:otherwise><Name>NEW</Name></xsl:otherwise>
                  </xsl:choose>
               </xsl:for-each>
        </Locations>
    </Destination>
</xsl:template>

输出

"Destination": [
    {
        "Locations": {
            "Name": [
                "ABC",
                "XYZ"
            ]
        },