【问题标题】:xsl choose in concatxsl 在 concat 中选择
【发布时间】:2013-08-01 05:42:01
【问题描述】:

我有以下数据:

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 不能与 select 语句一起使用,但如果没有它则效果很好。问题是我不能有负数,而是需要将它们转换为正数 (*-1) 并加上 400。

有什么想法吗?

【问题讨论】:

    标签: xslt concat valueconverter xsl-choose


    【解决方案1】:
    <?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>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-10-24
      • 1970-01-01
      • 1970-01-01
      • 2020-12-26
      • 2013-07-13
      相关资源
      最近更新 更多