如何从 XSLT 中的 JSON 中提取数据?

2024-03-04

我正在 XSLT 中调用休息服务,并获得 JSON 响应作为回报。

如何使用 XSLT 从 JSON 响应中提取数据。下面是用于调用其余服务的 XSLT 代码,并给出了 JSON 响应。我需要从 JSON 响应中提取以下值Cookie1, Cookie2 and Cookie3.

XSLT

<xsl:variable name="result1"> 
   <dp:url-open target="{$abc}" response="binaryNode" 
                resolve-mode="xml" data-type="xml" http-method="post">
   </dp:url-open>
</xsl:variable>

<xsl:variable name="json">
  <xsl:value-of select="dp:decode(dp:binary-encode($result1/result/binary/node()), 
                                  'base-64' )" />
</xsl:variable>

JSON 响应:

   {"mapData": 
     {
       "Cookie1": "KlzpP965iBw==",
       "status": "True",
       "Cookie2": "DDGT8mcsuzdMNNQ=",
       "Cookie3": "VERSION_4~mPpYUDcZnoJ0Z"
      }
   }

请让我知道如何使用 XSLT 执行此操作。


XSLT 3.0 / XPath 3.1

Use fn:parse-json() https://www.w3.org/TR/xpath-functions-31/#func-parse-json返回一个map https://www.w3.org/TR/xpath-functions-31/#dt-map, then map:get() https://www.w3.org/TR/xpath-functions-31/#func-map-get以获得感兴趣的值。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何从 XSLT 中的 JSON 中提取数据? 的相关文章

随机推荐