xsl-list
[Top] [All Lists]

Re: [xsl] Problem with base64encode.xsl

2008-07-18 06:54:01
Torsten Schassan schrieb:
Arithmetic operator is not defined for arguments of types (xs:string,
xs:double)
URL: http://www.w3.org/TR/xpath20/#ERRXPTY0004

The error points to this line in
<xsl:call-template name="binaryToDecimal">:

<xsl:with-param name="sum" select="$sum +
substring($binary,string-length($binary) ) * $power"/>

This works in loosely-typed XSL 1.0, but doesn't in strictly-typed XSL
2.0, which you are using.

(1) $binary is a string, so you can use string operations like
    string-length() and substring()
(2) You're using the result of these string operations with arithmetic
    operators like + and * ; this works in 1.0, but not in 2.0.
(3) In order for it to work in 2.0, use the number() function to
    convert the result of substring() to a number.

<xsl:transform version="2.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform";>
  <xsl:output method="text"/>
  <xsl:template match="/">
    <xsl:variable name="sum" select="3"/>
    <xsl:variable name="binary" select="'123456789'"/>
    <xsl:variable name="power" select="4"/>
    <xsl:value-of select="$sum +
      number( substring( $binary,string-length( $binary))) * $power"/>
    <xsl:text>&#10;</xsl:text>
  </xsl:template>
</xsl:transform>

Michael Ludwig

--~------------------------------------------------------------------
XSL-List info and archive:  http://www.mulberrytech.com/xsl/xsl-list
To unsubscribe, go to: http://lists.mulberrytech.com/xsl-list/
or e-mail: <mailto:xsl-list-unsubscribe(_at_)lists(_dot_)mulberrytech(_dot_)com>
--~--

<Prev in Thread] Current Thread [Next in Thread>