xslt - 计算 xslt 数组中的值
问题描述
我在 XSLT 下面有这个。
我想检查数组中特定元素的计数。
示例:-在这里我想检查A
数组中的计数。
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:map="http://www.w3.org/2005/xpath-functions/map"
xmlns:array="http://www.w3.org/2005/xpath-functions/array" exclude-result-prefixes="#all"
version="3.0">
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:param name="input"/>
<xsl:variable name="newline" select="' '"/>
<xsl:template match="/" name="xsl:initial-template">
<xsl:variable name="input-as-map" select="parse-json($input)" as="map(*)"/>
<root>
<!-- storing all the PERSONNUMBER present in the ibop -->
<xsl:variable name="array" as="element()*">
<Item>A</Item>
<Item>A</Item>
<Item>A</Item>
<Item>b</Item>
</xsl:variable>
<test>
<xsl:value-of select="count($array/Item='A')"/>
</test>
</root>
</xsl:template>
</xsl:stylesheet>
任何建议也会有所帮助............
解决方案
鉴于您的声明<xsl:variable name="array" as="element()*">
,您有一系列元素节点,而不是数组。而你想要count($array[. = 'A'])
。
推荐阅读
- php - 通过 env Facade 访问 .env 的内容
- c++ - windows下通过system()调用多个命令不起作用
- php - 单选按钮数组帖子
- css - 如何使用样式化组件创建共享样式?
- python - 来自 qt 设计器的最大化窗口
- python - 如何通过一维 Numpy 浮点数组在 for 循环中获取项目的实际值?
- android - Dagger-Hilt:为什么我们必须注释没有注入的活动
- javascript - 如何使时钟指针移动/旋转(html,css)
- c++ - 错误:需要左值作为一元“&”操作数 - Qt 中的信号连接
- java - 有没有办法使用 Jackson 和/或其相关库之一(csv、json 等)将字符串转换为 Java 类型?