ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> exslt
exslt
[exslt] Need help on using Math Functions
by Cathy T CIV NSWCCD W. Bethesda other posts by this author
May 16 2007 10:33AM messages near this date
[exslt] [Announce] Stylus Studio 2007 Release 2 Now Available | Re: [exslt] Need help on using Math Functions
& XSLT Hi there,

I want to call math:sqrt(input_argument) function. If I assign value of
price is a hard code, <xsl:variable name="price" select="25" /> , and
<xsl:variable name="sqrtOfPrice" select="math:sqrt($price)" />  , I don't
have any problem; However, if I define the price represents a value of a
node set, like <xsl:variable name="price"
select="catalog/cd/price[position()=1]" />  , then the
math:sqrt(input_argument) function can not recognize the value of price.
The error that I got as "Microsoft JScript runtime error Wrong number of
arguments or invalid property assignment line = 2, col = 20 (line is
offset ...". I tried to call math function at xsl:stylesheet section and
at xsl:template section. I still don't have any luck Please, some body
help me.

Below are my sample codes to call math:sqrt() function.

<!--cdcatalog.xml--> 
<?xml version="1.0" encoding="ISO-8859-1"?> 
<!-- Edited with XML Spy v2007 (http://www.altova.com) --> 
<?xml-stylesheet type="text/xsl" href="cdcatalog_stylesheet.xsl"?> 
<catalog> 
	<cd> 
		<title> Empire Burlesque</title>
		<artist> Bob Dylan</artist>
		<country> USA</country>
		<company> Columbia</company>
		<price> 10.90</price>
		<year> 1985</year>
	</cd> 
	<cd> 
		<title> Hide your heart</title>
		<artist> Bonnie Tyler</artist>
		<country> UK</country>
		<company> CBS Records</company>
		<price> 9.90</price>
		<year> 1988</year>
	</cd> 
</catalog> 

<!--cdcatalog_stylesheet.xsl--> 
<?xml version="1.0" encoding="ISO-8859-1"?> 
<!-- Edited with XML Spy v2007 (http://www.altova.com) --> 
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:math="http://exslt.org/math" extension-element-prefixes="math" > 
<xsl:import href="math/functions/sqrt/math.sqrt.msxsl.xsl" /> 
<xsl:variable name="price" select="catalog/cd/price[position()=1]" /> 
<!--
<xsl:variable name="value" select="math:sqrt($price)" /> 
--> 
<xsl:template match="/"> 
  <html> 
  <body> 
    <h2> My CD Collection</h2>
    <table border="1"> 
      <tr bgcolor="#9acd32"> 
        <th> Title</th>
        <th> Artist</th>
        <th> Price</th>
        <th> SqrtOfPrice</th>
     </tr> 
      <xsl:for-each select="catalog/cd"> 
      <xsl:sort select="artist" /> 10:51 AM 5/14/2007
      <tr> 
        <td> <xsl:value-of select="title"/></td>
        <td> <xsl:value-of select="artist"/></td>
        <td> <xsl:value-of select="$price"/></td>
        <td> <xsl:value-of select="math:sqrt($price)"/></td>
      </tr> 
      </xsl:for-each> 
    </table> 
  </body> 
  </html> 
</xsl:template> 
</xsl:stylesheet> 
Thread:
Cathy T CIV NSWCCD W. Bethesda
Florent Georges
Florent Georges
James Fuller

Privacy Policy | Email Opt-out | Feedback | Syndication
© 2004 ActiveState, a division of Sophos All rights reserved