0

我有以下数据:

XML

<team>
    <rectx>30</rectx>
    <diadata>
        <bestAnd>-350</bestAnd>
    </diadata>
    <diadata>
        <bestAnd>-250</bestAnd>
    </diadata>
    <diadata>
        <bestAnd>-50</bestAnd>
    </diadata>
</team>

XSL

<xsl:variable name="list">
    <xsl:value-of select="'M'" />
    <xsl:for-each select="/team/diadata/bestAnd">
        <xsl:choose>
            <xsl:when test=". &lt;0">
                <xsl:value-of select=".*-1+400" />
            </xsl:when>
            <xsl:otherwise>
                <xsl:value-of select="." />
            </xsl:otherwise>
        </xsl:choose>
        <xsl:variable name="position" select="position()" />
        <xsl:value-of select="concat(/team/rectx*$position+40,' ',.,' L')" />

    </xsl:for-each>

</xsl:variable>

<xsl:variable name="finallist">
    <xsl:value-of select="substring($list, 1, string-length($list) - 2)" />
</xsl:variable>


<text x="250" y="50"
    style="font-family: Arial;
                 font-size  : 24;
                 stroke     : #000000;
                 fill       : #000000;">
    <xsl:value-of select="$finallist" />
</text>  

输出必须是

M70 750 L100 650 L130 450

但是对于选择语句,它是

M75070 -350 L650100 -250 L450130 -50

所以它在计算之后执行“字母”“y-val”“x-val”“y-val”

我不明白为什么 concat 不能与选择语句一起使用,但如果没有它,效果很好。问题是我不能有负数,而是需要将它们转换为正数 (*-1) 并加上 400。

有任何想法吗?

4

1 回答 1

2
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/">
    <xsl:variable name="list">
        <xsl:value-of select="'M'"/>
        <xsl:for-each select="/team/diadata/bestAnd">
                    <xsl:variable name="position" select="position()"/>
            <xsl:value-of select="concat(/team/rectx*$position+40,' ')"/>
            <xsl:choose>
                <xsl:when test=". &lt;0">
                    <xsl:value-of select=".*-1+400"/>
<xsl:value-of select="' L'"/>
                </xsl:when>
                <xsl:otherwise>
                    <xsl:value-of select="."/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:for-each>
    </xsl:variable>
</xsl:template>
</xsl:stylesheet>
于 2012-11-13T11:09:47.427 回答