【问题标题】:How to fetch data from array of list in xslt如何从xslt中的列表数组中获取数据
【发布时间】:2022-11-17 22:05:34
【问题描述】:

我正在使用 xslt 3.0(saxon-HE v11.4 库)在 Java 中将 json 转换为 xml。

需要帮助从数组中提取值

示例输入 json

{
"Details":{
"name":["a","b","c"]
}
}

要求输出以下格式

<Details>
<name indexarray="0">a</name>
<name indexarray="1">b</name>
<name indexarray="2">c</name>
</Details>

【问题讨论】:

    标签: arrays json xml for-loop xslt-3.0


    【解决方案1】:

    好吧,使用 Saxon 11,您可以从字面上用例如-json:input.json 到 XSLT,然后匹配例如.[. instance of map(*)]

    <?xml version="1.0" encoding="utf-8"?>
    <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
      version="3.0"
      xmlns:xs="http://www.w3.org/2001/XMLSchema"
      exclude-result-prefixes="#all"
      expand-text="yes">
      
    <xsl:output indent="yes"/>
    
    <xsl:template match=".[. instance of map(*)]">
      <Details>
        <xsl:iterate select="?Details?name?*">
          <name indexarray="{position() - 1}">{.}</name>
        </xsl:iterate>
      </Details>
    </xsl:template>
      
    </xsl:stylesheet>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-02
      • 1970-01-01
      • 2012-05-21
      • 1970-01-01
      • 2020-05-04
      相关资源
      最近更新 更多