tags:

views:

42

answers:

2

    <xsl:apply-templates select="xslTutorial"/>
</xsl:template>
<xsl:template match="xslTutorial">
<p>
        <xsl:for-each select="number">

        <xsl:value-of select="."/>+
        </xsl:for-each>
        =
        <xsl:value-of select="sum(number)"/>
</p>
</xsl:template>

in the result there is a"+" that i don't it to be shown i want the result to be 1 + 3 + 17 + 11 = 32 but the result is 1 + 3 + 17 + 11 += 32 what i do to prevent the last +

+3  A: 

you need to ensure the last iteration doesn't include the "+":

<xsl:apply-templates select="xslTutorial"/>

<!--</xsl:template> was this a typo? -->

<xsl:template match="xslTutorial">
  <p>
    <xsl:for-each select="number">
      <xsl:value-of select="."/>
      <xsl:if test="position() != last()">+</xsl:if>
    </xsl:for-each>
    =
    <xsl:value-of select="sum(number)"/>
  </p>
</xsl:template>
scunliffe
A: 

You don't have any logic that would prevent it from putting out the "+".

Something like this would work:

<xsl:template match="xslTutorial">
    <p>
        <xsl:for-each select="number">

            <xsl:value-of select="."/>
            <xsl:if test="not(position()=last())">+</xsl:if>
        </xsl:for-each>
        =
        <xsl:value-of select="sum(number)"/>
    </p>
</xsl:template>
Mads Hansen