Question

I have the following data:

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>  

The output has to be

M70 750 L100 650 L130 450

however with the choose statement it is

M75070 -350 L650100 -250 L450130 -50

so it does "letter""y-val after calc""x-val" "y-val"

I can't understand why the concat does not work with the choose statement but without it works great. Prob is that I can't have negative numbers but instead need to take those and convert them to positive (*-1) and add 400.

Any ideas?

Was it helpful?

Solution

<?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>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top