xsl-list
[Top] [All Lists]

Re: How to test FXSL for XSLT2

2004-11-26 03:03:28
FXSL for XSLT2 was put on SourceForge.net more than a year ago. It was
and still is a work in progress.

The first goal was to have all stylesheet modules functioning with
Saxon 7.x with no or minimal changes -- essentially leaving them as
written for  XSLT 1.0 . This was achieved almost immediately without
any major problems.

The second goal was to upgrade most of the templates to use XSLT 2.0
-- most importantly wherever possible templates were converted to
xsl:function. One tricky problem (solved successfully) was to
implement default values for parameters of an xsl:function (with
certain well expressed limitations). This was also achieved, although
they may not run the same way with newer versions of Saxon, especially
after November 2003.

All names of upgraded stylesheet modules begin with "func-", followed
by the name of the (major) function or functiongroup implemented in
that module -- for example: "func-foldl.xsl", "func-foldl-tree.xsl",
"func-foldr.xsl", "func-trignm.xsl", etc.

At present there are 49 such stylesheet modules in the library.

The names of the stylesheet modules used for testing also follow a
strict convention:

"testFunc-Exp.xsl", "testFunc-ScanIter4.xsl", "testFunc-zipWith.xsl", ... etc.

There are 52 such stylesheet modules in the library.

An example of a test:

testFunc-Scanl.xsl
==============

<xsl:stylesheet version="2.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
xmlns:f="http://fxsl.sf.net/";
xmlns:myAdd="f:myAdd"
xmlns:myParam="f:myParam"
  exclude-result-prefixes="f myAdd myParam"

  <xsl:import href="func-scanl.xsl"/>
  
  <!-- To be applied on numList.xml -->
  <xsl:output omit-xml-declaration="yes" indent="yes"/>

  <xsl:template match="/">
   
    <xsl:variable name="vFun" select="document('')/*/myAdd:*[1]"/>
    <xsl:variable name="vZero" select="document('')/*/myParam:*[1]"/>

    <xsl:value-of select="f:scanl($vFun, 0, /*/*)"/>
       
    <xsl:text>&#xA;- - - - - - - - - - -&#xA;</xsl:text>
    
     <xsl:value-of select="f:scanl1($vFun, /*/*)"/>
  </xsl:template>
  
  <myAdd:myAdd/>
  <xsl:template match="myAdd:*">
    <xsl:param name="arg1" select="0"/>
    <xsl:param name="arg2" select="0"/>
  
    <xsl:value-of select="$arg1 + $arg2"/>
  </xsl:template>
  
</xsl:stylesheet>

Another convention (as seen from the above code) is that in the
testing stylesheet there is a comment, specifying which file contains
the source xml document, on which the transformation is to be applied.
In this case this is the file:

numList.xml
=========

<nums>
  <num>01</num>
  <num>02</num>
  <num>03</num>
  <num>04</num>
  <num>05</num>
  <num>06</num>
  <num>07</num>
  <num>08</num>
  <num>09</num>
  <num>10</num>
</nums>

The result with Saxon 8.0 from Saxonica and Java version 1.4.2_04 is:

0 1 3 6 10 15 21 28 36 45 55
- - - - - - - - - - -
01 3 6 10 15 21 28 36 45 55


As can be expected from a function named "scanl", the results are the
partial sums of the sequence of numbers 1 to 10, calculated in two
different ways (with or without an initial element).

Of course, the result is identical if we use  1 to 10 as the last
argument in the two function calls.

Let's take another example:


testFunc-Trig.xsl
============

<xsl:stylesheet version="2.0" 
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform";
 xmlns:xs="http://www.w3.org/2001/XMLSchema";
 xmlns:f="http://fxsl.sf.net/";
 exclude-result-prefixes="xs f" 

 
 <xsl:import href="func-trignm.xsl"/>
 <!-- To be applied on any xml file -->

 <xsl:output method="text"/>
  
  <xsl:template match="/">
         <xsl:value-of select="f:cos(240, .00000001, 'deg')"/>
   <xsl:text>&#xA;</xsl:text>
   <xsl:for-each select="(1 to 10)">
      <xsl:variable name="x" select="xs:double(.)"/>
     <xsl:copy-of select="('sin^2(', ., ') + cos^2(', ., ') = ',
f:cos($x)*f:cos($x) + f:sin($x)*f:sin($x), '&#xA;')"/>
   </xsl:for-each>
   
   <xsl:for-each select="(1 to 10)">
      <xsl:variable name="x" select="xs:double(.)"/>
     <xsl:copy-of select="('sin^2(', ., ') + cos^2(', ., ') = ', 
                          f:cos($x, 0.01)*f:cos($x, 0.01) 
                          + f:sin($x, 0.01)*f:sin($x, 0.01), 
                          '&#xA;')"/>
   </xsl:for-each>
   
   <xsl:for-each select="(1 to 10)">
      <xsl:variable name="x" select="xs:double(.)"/>
     <xsl:copy-of select="('tan(', ., ') * cot(', ., ') = ',
f:tan($x)*f:cot($x), '&#xA;')"/>
   </xsl:for-each>
  </xsl:template>
</xsl:stylesheet>

As indicated by the value of the comment node:

 <!-- To be applied on any xml file -->

the above transformation may be applied on any source xml file and it
does not use it.

The result with Saxon 8.0 from Saxonica and Java version 1.4.2_04 is:

-0.5000000000079126
sin^2( 1 ) + cos^2( 1 ) =  1.0000000000011215 
 sin^2( 2 ) + cos^2( 2 ) =  0.9999999999473589 
 sin^2( 3 ) + cos^2( 3 ) =  0.999999999351915 
 sin^2( 4 ) + cos^2( 4 ) =  1.0000000001438516 
 sin^2( 5 ) + cos^2( 5 ) =  0.9999999999993836 
 sin^2( 6 ) + cos^2( 6 ) =  0.9999999997198752 
 sin^2( 7 ) + cos^2( 7 ) =  0.9999999999661757 
 sin^2( 8 ) + cos^2( 8 ) =  0.9999999998548059 
 sin^2( 9 ) + cos^2( 9 ) =  1.0000000000612523 
 sin^2( 10 ) + cos^2( 10 ) =  1.0000000002883653 
 sin^2( 1 ) + cos^2( 1 ) =  1.0003335729961926 
 sin^2( 2 ) + cos^2( 2 ) =  1.0002903927449274 
 sin^2( 3 ) + cos^2( 3 ) =  0.9997634950520358 
 sin^2( 4 ) + cos^2( 4 ) =  0.9994876711561005 
 sin^2( 5 ) + cos^2( 5 ) =  0.9996433062890346 
 sin^2( 6 ) + cos^2( 6 ) =  1.0002658755812832 
 sin^2( 7 ) + cos^2( 7 ) =  1.0001232745113593 
 sin^2( 8 ) + cos^2( 8 ) =  0.9994993721060835 
 sin^2( 9 ) + cos^2( 9 ) =  0.9994946072942865 
 sin^2( 10 ) + cos^2( 10 ) =  0.9998544711984396 
 tan( 1 ) * cot( 1 ) =  1 
 tan( 2 ) * cot( 2 ) =  0.9999999999999999 
 tan( 3 ) * cot( 3 ) =  1 
 tan( 4 ) * cot( 4 ) =  1 
 tan( 5 ) * cot( 5 ) =  1 
 tan( 6 ) * cot( 6 ) =  1 
 tan( 7 ) * cot( 7 ) =  1 
 tan( 8 ) * cot( 8 ) =  1 
 tan( 9 ) * cot( 9 ) =  1 
 tan( 10 ) * cot( 10 ) =  0.9999999999999999 


One last remark is that any questions about FXSL have the best chance
to receive a correct answer in a timely manner, if posted in the
appropriate FXSL mailing list or directly to me.


Many thanks personally to Mike Kay for his remarkable work on XSLT
2.0, for his books and for Saxon -- it is always a pleasure to be in
touch with his work.

Hope this helped.

Cheers,
Dimitre.


On 23 Nov 2004 11:08:20 +0000, Colin Paul Adams
<colin(_at_)colina(_dot_)demon(_dot_)co(_dot_)uk> wrote:
I can't find any instructions.
--
Colin Paul Adams
Preston Lancashire

--~------------------------------------------------------------------
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>
--~--



--~------------------------------------------------------------------
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>