如何在使用1.0版的XSLT中执行此操作

时间:2017-09-29 21:11:03

标签: xslt

使用此字符串定义与因子对应的数字列表:24850973612485097361

数字被翻转并且每个数字乘以对应于其位置的因子,0对应于10并且所有累计

例如,对于编号为28200703的订单:

翻了一个号码,给出30700282

使用因子字符串24850973612485097361作为数字的相应大小,计算如下:

3 x 2 = 6

0 x 4 = 0

7 x 8 = 56

0 x 5 = 0

0 x 10 = 0

2 x 9 = 18

8 x 7 = 56

2 x 3 = 6

累积:142

1 个答案:

答案 0 :(得分:0)

以这种方式尝试:

<xsl:template name="process">
    <xsl:param name="number"/>
    <xsl:param name="factors" select="'24850973612485097361'"/>
    <xsl:param name="accumulated" select="0"/>
    <xsl:choose>
        <xsl:when test="$number">
            <xsl:variable name="n" select="$number mod 10" />
            <xsl:variable name="m" select="substring($factors, 1, 1)" />
            <xsl:call-template name="process">
                <xsl:with-param name="number" select="floor($number div 10)"/>
                <xsl:with-param name="factors" select="substring($factors, 2)"/>
                <xsl:with-param name="accumulated" select="$accumulated + $n * $m" />
            </xsl:call-template>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$accumulated"/>
        </xsl:otherwise>
    </xsl:choose>
</xsl:template>

电话示例:

<xsl:call-template name="process">
    <xsl:with-param name="number" select="28200703"/>
</xsl:call-template>

演示:http://xsltransform.net/3MvmrAF