Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XSLT
|
XSLT General questions and answers about XSLT. For issues strictly specific to the book XSLT 1.1 Programmers Reference, please post to that forum instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XSLT section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 20th, 2003, 09:03 AM
Authorized User
 
Join Date: Jun 2003
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default javascript problem in stylesheet extension

Hi folks,

I'm trying to use this function in a stylesheet. (this is just the beginning, I plan to develop it further)

<msxsl:script language="JScript" implements-prefix="numberfunctions"><![CDATA[

    function getMax(n){
        n=parseFloat(n);
        n = isNaN(n) ? 0 : n.toExponential();
        return n;
    }

]]></msxsl:script>

the toExponential() method causes this error:

Microsoft JScript runtime error Wrong number of arguments or invalid property assignment line = 4, col = 2 (line is offset from the start of the script block). Error returned from property or method call.

When I use this function in a normal HTML page it works fine... its almost like the stylesheet extension is using an older version of javascript that does not support this method. Any ideas folks?
 
Old June 27th, 2003, 09:58 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Works fine on my machine. Can we see the full stylesheet and if relevant xml?

--

Joe
 
Old June 27th, 2003, 10:10 AM
Authorized User
 
Join Date: Jun 2003
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hi Joe,

Trust me, you don't want to see the whole stylesheet - its massive!!

Anyway, the relevant bit is as follows

(it determines the highest value in the data)

<xsl:variable name="HighValue_actual" select="PROFREP:total[@month &gt; 0]/@actual_value[not(../../PROFREP:total[@month &gt; 0]/@actual_value &gt; .)]" />
    <xsl:variable name="HighValue_profile" select="PROFREP:total[@month &gt; 0]/@profile_value[not(../../PROFREP:total[@month &gt; 0]/@profile_value &gt; .)]" />
    <xsl:variable name="HighValue">
        <xsl:choose>
        <xsl:when test="$HighValue_actual &gt; $HighValue_profile">
            <xsl:value-of select="$HighValue_actual"/>
        </xsl:when>
        <xsl:otherwise>
            <xsl:value-of select="$HighValue_profile"/>
        </xsl:otherwise>
        </xsl:choose>
    </xsl:variable>

<div style="left:0;top:0;"><xsl:value-of select="numberfunctions:getMax($HighValue)"/></div>

The XML is many rows of data like this

<PROFREP:category code="AL" traincat="AMA" target="8">
  <PROFREP:total month="0" profile_value="0" actual_value="8" perc_value="100" />
  <PROFREP:total month="1" profile_value="0" actual_value="0" perc_value="0" />
  <PROFREP:total month="2" profile_value="0" actual_value="1" perc_value="12.5" />
  <PROFREP:total month="3" profile_value="0" actual_value="0" perc_value="12.5" />
  <PROFREP:total month="4" profile_value="0" actual_value="0" perc_value="12.5" />
  <PROFREP:total month="5" profile_value="0" actual_value="0" perc_value="12.5" />
  <PROFREP:total month="6" profile_value="0" actual_value="0" perc_value="12.5" />
  <PROFREP:total month="7" profile_value="0" actual_value="0" perc_value="12.5" />
  <PROFREP:total month="8" profile_value="0" actual_value="0" perc_value="12.5" />
  <PROFREP:total month="9" profile_value="0" actual_value="0" perc_value="12.5" />
  <PROFREP:total month="10" profile_value="0" actual_value="2" perc_value="37.5" />
  <PROFREP:total month="11" profile_value="4" actual_value="3" perc_value="75" />
  <PROFREP:total month="12" profile_value="4" actual_value="2" perc_value="100" />
  </PROFREP:category>
 
Old June 27th, 2003, 10:21 AM
Authorized User
 
Join Date: Jun 2003
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

basically what I'm trying to do here is determine a suitable range for the Y-axis of a graph of that data, so if anyone can come up with a way by barking up a different tree then that would be cool too.

The diversity of values is too great to do a simple multiple where clause... some of these might be in the range 0-5, some may be in the range 0-10,000,000.

Thats why I was thinking along the lines of extracting the value as an exponential so i can choose a value and then multiply it by the relevant number of tens.
 
Old June 27th, 2003, 10:44 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Well as you say it might be using a different version of JScript. How are you performing the transform. Can you try running the code below?
Code:
<?xml version='1.0' encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:numberfunctions="myUrn">
  <msxsl:script language="JScript" implements-prefix="numberfunctions"><![CDATA[


   function getScriptEngineInfo()
   {
     var s;
     s = ""; // Build string with necessary info.
     s += ScriptEngine() + " Version ";
     s += ScriptEngineMajorVersion() + ".";
     s += ScriptEngineMinorVersion() + ".";
     s += ScriptEngineBuildVersion();
     return(s);
   }


]]></msxsl:script>
  <xsl:template match="/">
        <xsl:value-of select="numberfunctions:getScriptEngineInfo()"/>
  </xsl:template>
</xsl:stylesheet>
against any xml file and then from a web page to see if there's a difference?

--

Joe
 
Old June 27th, 2003, 10:52 AM
Authorized User
 
Join Date: Jun 2003
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

it says JScript Version 5.5.6330 which is what I would expect it to be using, same as JScript for normal use in client side scripting... I wonder why it won't recognise that method then?
 
Old June 28th, 2003, 03:44 AM
joefawcett's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 3,074
Thanks: 1
Thanked 38 Times in 37 Posts
Default

Well the only other thing is that there may be some restrictions on what numbers it can handle. Does it each time it is called or just sometimes. Perhaps you could use a try/catch block to trap the error and output a distinct value if it errored.

--

Joe
 
Old June 30th, 2003, 05:57 AM
Authorized User
 
Join Date: Jun 2003
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I've tried the Try/Catch - it just gives me [object Error]

I may have to give up on doing it in the stylesheet, and instead work out the values elsewhere and feed them in.
 
Old June 30th, 2003, 11:06 AM
Authorized User
 
Join Date: Jun 2003
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I've got to the bottom of this... yet again I was wasting time looking in totally the wrong place for the error.

I should have called numberfunctions:getMax(number($HighValue))

I guess the function must have seen the incoming parameter as a node rather than a number, hence that method not being available.

How annoying is that!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Context Menu Shell Extension problem aldwinenriquez .NET Framework 2.0 1 December 18th, 2007 07:35 AM
DATA PROCESSING EXTENSION PROBLEM rodoxdolfo BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 1 May 11th, 2006 02:38 PM
Using Stylesheet on Reports murali.tk BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 1 April 17th, 2006 09:47 PM
XSL Stylesheet Problem Ben Horne XSLT 4 March 6th, 2004 05:50 AM
Problem with Extension php_gd.dll lcorzberg BOOK: Beginning PHP4/PHP 5 ISBN: 978-0-7645-4364-7; v5 ISBN: 978-0-7645-5783-5 1 September 25th, 2003 11:52 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.