Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/.net/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# xslt V1.0-带有递归循环的子模板返回空值_C#_.net_Xml_Xslt_Xslt 1.0 - Fatal编程技术网

C# xslt V1.0-带有递归循环的子模板返回空值

C# xslt V1.0-带有递归循环的子模板返回空值,c#,.net,xml,xslt,xslt-1.0,C#,.net,Xml,Xslt,Xslt 1.0,我试图得到每个簇的child之和的最大值 集群1:10+20=30 cluster2:20+30=50-->50是最高值 问题:子模板的返回值为“”。 为什么?变量tempMax正在获取一个包含我的编号的节点,而不仅仅是一个编号 $tempMax = {Dimension:[1]} + [1] = / + + node()[1] = 50 我怎样才能解决这个问题?(xslt v1.0) xml: 分配tempMax时缺少相反的情况: <xsl:variable na

我试图得到每个簇的child之和的最大值

  • 集群1:10+20=30

  • cluster2:20+30=50-->50是最高值

问题:子模板的返回值为“”。
为什么?变量tempMax正在获取一个包含我的编号的节点,而不仅仅是一个编号

$tempMax = {Dimension:[1]}
+ [1] = /
+ + node()[1] = 50
我怎样才能解决这个问题?(xslt v1.0)


xml:


分配
tempMax
时缺少相反的情况:

        <xsl:variable name="tempMax">
            <xsl:if test="$max &lt; $barSum">
                <xsl:value-of select="$barSum"/>
            </xsl:if>      
            <xsl:if test="$max >= $barSum">
                <xsl:value-of select="$max"/>
            </xsl:if>
        </xsl:variable>
应用于问题中提供的输入,返回
50

应用于此更改的输入:

<column-chart-stacked-full>
    <clusters>
        <cluster number="1">
            <bar>
                <value>10</value>
            </bar>
            <bar>
                <value>20</value>
            </bar>
        </cluster>
        <cluster number="2">
            <bar>
                <value>20</value>
            </bar>
            <bar>
                <value>30</value>
            </bar>
        </cluster>
                <cluster number="1">
            <bar>
                <value>10</value>
            </bar>
            <bar>
                <value>20</value>
            </bar>
        </cluster>
        <cluster number="2">
            <bar>
                <value>70</value>
            </bar>
            <bar>
                <value>30</value>
            </bar>
        </cluster>
    </clusters>
</column-chart-stacked-full>

10
20
20
30
10
20
70
30

返回
100

+1一个改进想法:
xsl:choose
可能比两个
xsl:if
更合适。我再次调试了我的代码,$max仍然返回数值的instaid?这很奇怪。在给你答案之前,我已经执行了你的代码;而且效果很好。我将提供一个新的反馈。我尝试了另一个带有saxon XSLT处理器的调试器,它正在工作。我认为.net XSLT处理器正在制造一个数字到字符串更改的问题。。当tempMax获得一个数值时,它将变为string。使用大量的number()已修复此问题:)。谢谢你的帮助。
$max = {Dimension:[1]}
+ [1] = /
+ + node()[1] = 50
        <xsl:variable name="tempMax">
            <xsl:if test="$max &lt; $barSum">
                <xsl:value-of select="$barSum"/>
            </xsl:if>      
            <xsl:if test="$max >= $barSum">
                <xsl:value-of select="$max"/>
            </xsl:if>
        </xsl:variable>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output indent="yes"/>

    <xsl:template match="/">
        <xsl:call-template name="findMaxClusterVal"/>
    </xsl:template>

    <xsl:template name="findMaxClusterVal">
        <xsl:param name="count" select="count(column-chart-stacked-full/clusters/cluster)"/>
        <xsl:param name="limit" select="$count"/>
        <xsl:param name="max" select="0"/>
        <xsl:if test="$count &gt; 0">
            <xsl:variable name ="barSum" select="sum(column-chart-stacked-full/clusters/cluster[$count]/bar/value)"/>
            <xsl:variable name="tempMax">
                <xsl:choose>
                    <xsl:when test="$max &lt; $barSum">
                        <xsl:value-of select="$barSum"/>
                    </xsl:when>
                    <xsl:otherwise>
                        <xsl:value-of select="$max"/>
                    </xsl:otherwise>
                </xsl:choose>
            </xsl:variable>
            <!-- recursive loop -->
            <xsl:call-template name="findMaxClusterVal">
                <xsl:with-param name="count" select="$count - 1"/>
                <xsl:with-param name="limit" select="$limit"/>
                <xsl:with-param name="max" select="$tempMax"/>
            </xsl:call-template>
        </xsl:if>
        <!-- return max value -->
        <xsl:if test="$count = 0">
            <xsl:value-of select="$max"/>
        </xsl:if>
    </xsl:template>

</xsl:stylesheet>
<column-chart-stacked-full>
    <clusters>
        <cluster number="1">
            <bar>
                <value>10</value>
            </bar>
            <bar>
                <value>20</value>
            </bar>
        </cluster>
        <cluster number="2">
            <bar>
                <value>20</value>
            </bar>
            <bar>
                <value>30</value>
            </bar>
        </cluster>
                <cluster number="1">
            <bar>
                <value>10</value>
            </bar>
            <bar>
                <value>20</value>
            </bar>
        </cluster>
        <cluster number="2">
            <bar>
                <value>70</value>
            </bar>
            <bar>
                <value>30</value>
            </bar>
        </cluster>
    </clusters>
</column-chart-stacked-full>