Altova Mailing List Archives

RE: [xsl] 1 + 1 = 11

From: Wendell Piez <wapiez@---------------->
Date: 4/18/2006 5:42:00 PM
At 01:31 PM 4/18/2006, it was written:
I'm trying to remember, but isn't "+" used for concatenation?  So, yes,

Nope, it isn't, not in XSLT (or more precisely, XPath).

I think the problem is the <xsl:otherwise>0</xsl:otherwise>. My guess 
is that the test is being run on a table with two rows: the first has 
an index of '1' assigned, so '1' is appended. The next (position()=2) 
hits the otherwise so '0' is appended, resulting in the string '10'. 
XPath coerces this string to 10, add 1 to it and get 11.

If you had a table with three rows, you'd get 101, four rows would 
get 1001, etc.

If this is correct, just change the <xsl:choose> to an <xsl:if> to 
get rid of the otherwise clause. It shouldn't be there anyway.


> -----Original Message-----
> From: Eric White [mailto:eric.white@xxxxxxxxxxx]
> Sent: Tuesday, April 18, 2006 1:19 PM
> To: xsl-list@xxxxxxxxxxxxxxxxxxxxxx
> Subject: [xsl] 1 + 1 = 11
> What am I missing?  I define a parameter, get the highest
> existing row number and I want to add a value to it -- so I
> can add the next table row with a new index.  I get the index
> value correctly, but when I add one (1) to it, I get  the
> string "11", rather than the number 2. Note that I
> specifically set the param to a number via the number() function.
> I've also tried using the number() function inside the select
> attribute of the apply-templates element, trying to coerce
> the result, but to no avail.
> <xsl:template match="ntpServerTable">
>    <xsl:param name="rowindex">
>       <xsl:for-each select="ntpServerTableRow">
>          <xsl:sort select="ntpServerTableRowIndex" data-type="number"
> order="descending" />
>         <xsl:choose>
>            <xsl:when test="position() = 1">
>              <xsl:value-of select="number(ntpServerTableRowIndex)"/>
>           </xsl:when>
>           <xsl:otherwise>0</xsl:otherwise>
>        </xsl:choose>
>      </xsl:for-each>
>    </xsl:param>
>    <xsl:apply-templates select="ntpServerTableRow"/>
>    <ntpServerTableRowIndex><xsl:value-of
> select="$rowindex+1"/></ntpServerTableRowIndex>

Wendell Piez                            mailto:wapiez@xxxxxxxxxxxxxxxx
Mulberry Technologies, Inc.      
17 West Jefferson Street                    Direct Phone: 301/315-9635
Suite 207                                          Phone: 301/315-9631
Rockville, MD  20850                                 Fax: 301/315-8285
  Mulberry Technologies: A Consultancy Specializing in SGML and XML


These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.