2012-11-13 24 views
0

選擇,我有以下數據:XSL的Concat

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不會與choose語句一起工作,但如果沒有,它的效果很好。普羅布是我不能有負數,但需要採取這些,並將其轉換爲正(* -1),並添加400.

任何想法?

回答

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> 
+0

哇謝謝偉大的作品。 – Thevagabond