首页 > 解决方案 > 计算 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="'&#10;'"/>
    <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>

任何建议也会有所帮助............

标签: xslt

解决方案


鉴于您的声明<xsl:variable name="array" as="element()*">,您有一系列元素节点,而不是数组。而你想要count($array[. = 'A'])


推荐阅读