How to make a simple running example using packages?

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

How to make a simple running example using packages?

Dimitre Novatchev
Hi,

Using the trial version of Saxon 9.6EE and the example package from
the latest XSLT 3.0 Last Call, I am trying to produce a simple,
running example:

using-package.xsl:
==============
<xsl:package name="http://example.org/complex-arithmetic.xsl"
  package-version="1.0"  version="3.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:f="http://example.org/complex-arithmetic.xsl">
  <xsl:use-package name="complex-arithmetic"/>

  <xsl:template match="/">
    <xsl:variable name="vComplex1" select="f:complex-number(1, 0)"
as="map(xs:integer, xs:double)"/>
    Real:      <xsl:sequence select="$vComplex1(0)"/>
    Imaginary: <xsl:sequence select="$vComplex1(1)"/>
  </xsl:template>
</xsl:package>



complex-arithmetic.xsl:
=================
<xsl:package name="complex-arithmetic"
  package-version="1.0"  version="3.0"
  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
  xmlns:xs="http://www.w3.org/2001/XMLSchema"
  xmlns:f="http://example.org/complex-arithmetic.xsl">

  <xsl:function name="f:complex-number"
                as="map(xs:integer, xs:double)" visibility="public">
    <xsl:param name="real" as="xs:double"/>
    <xsl:param name="imaginary" as="xs:double"/>
    <xsl:sequence select="map{ 0:$real, 1:$imaginary }"/>
  </xsl:function>

  <xsl:function name="f:real"
                as="xs:double" visibility="public">
    <xsl:param name="complex" as="map(xs:integer, xs:double)"/>
    <xsl:sequence select="$complex(0)"/>
  </xsl:function>

  <xsl:function name="f:imag"
                as="xs:double" visibility="public">
    <xsl:param name="complex" as="map(xs:integer, xs:double)"/>
    <xsl:sequence select="$complex(1)"/>
  </xsl:function>

  <xsl:function name="f:add"
                as="map(xs:integer, xs:double)" visibility="public">
    <xsl:param name="x" as="map(xs:integer, xs:double)"/>
    <xsl:param name="y" as="map(xs:integer, xs:double)"/>
    <xsl:sequence select="
         f:complex-number(
           f:real($x) + f:real($y),
           f:imag($x) + f:imag($y)"/>
  </xsl:function>

  <xsl:function name="f:multiply"
                as="map(xs:integer, xs:double)" visibility="public">
    <xsl:param name="x" as="map(xs:integer, xs:double)"/>
    <xsl:param name="y" as="map(xs:integer, xs:double)"/>
    <xsl:sequence select="
         f:complex-number(
           f:real($x)*f:real($y) - f:imag($x)*f:imag($y),
           f:real($x)*f:imag($y) + f:imag($x)*f:real($y))"/>
  </xsl:function>

  <!-- etc. -->
</xsl:package>

When I run Saxon 9.6 on using-package.xsl, I get these error messages:

Saxon-EE 9.6.0.1J from Saxonica
Java version 1.7.0_51
Using license serial number Vxxxxxxxxxxxxxxx

Error at xsl:use-package on line 6 column 47 of marrowtr.xsl:
  XTSE3000: Package complex-arithmetic was not found

Error at xsl:variable on line 9 column 101 of marrowtr.xsl:
  XPST0017 XPath syntax error at char 0 on line 9 in {f:complex-number(1, 0)}:
    Cannot find a matching 2-argument function named
  {http://example.org/complex-arithmetic.xsl}complex-number()

Stylesheet compilation failed: 2 errors reported


What should I do in order to make this simple example run as expected?

It is not clear to me how finding a package given its name works -- I
also tried importing complex-arithmetic.xsl into using-package.xsl,
but got this error:

"Error at xsl:import on line 8 column 46 of marrowtr.xsl:
  XTSE0165: Included document complex-arithmetic.xsl is not a stylesheet"


Any guidance how to produce a running example is enormously appreciated.


--
Cheers,
Dimitre Novatchev

------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|

Re: How to make a simple running example using packages?

Michael Kay
If you are running from the command line, it is possible to load multiple packages by providing a semicolon-separated list of filenames in the -xsl parameter. However, I don't think this is well documented or tested and it may have restrictions concerning the order of packages.

What is documented and tested is using packages via the s9api XsltCompiler interface; essentially you can compile a package into a CompiledPackage object, and then make this available to an XsltCompiler using an importPackage method.

This is a bit of a stopgap; packages are work in progress. We're thinking about "classpath-like" mechanisms for the longer term.

Michael Kay
Saxonica
[hidden email]
+44 (0) 118 946 5893




On 19 Oct 2014, at 00:46, Dimitre Novatchev <[hidden email]> wrote:

> Hi,
>
> Using the trial version of Saxon 9.6EE and the example package from
> the latest XSLT 3.0 Last Call, I am trying to produce a simple,
> running example:
>
> using-package.xsl:
> ==============
> <xsl:package name="http://example.org/complex-arithmetic.xsl"
>  package-version="1.0"  version="3.0"
>  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>  xmlns:xs="http://www.w3.org/2001/XMLSchema"
>  xmlns:f="http://example.org/complex-arithmetic.xsl">
>  <xsl:use-package name="complex-arithmetic"/>
>
>  <xsl:template match="/">
>    <xsl:variable name="vComplex1" select="f:complex-number(1, 0)"
> as="map(xs:integer, xs:double)"/>
>    Real:      <xsl:sequence select="$vComplex1(0)"/>
>    Imaginary: <xsl:sequence select="$vComplex1(1)"/>
>  </xsl:template>
> </xsl:package>
>
>
>
> complex-arithmetic.xsl:
> =================
> <xsl:package name="complex-arithmetic"
>  package-version="1.0"  version="3.0"
>  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>  xmlns:xs="http://www.w3.org/2001/XMLSchema"
>  xmlns:f="http://example.org/complex-arithmetic.xsl">
>
>  <xsl:function name="f:complex-number"
>                as="map(xs:integer, xs:double)" visibility="public">
>    <xsl:param name="real" as="xs:double"/>
>    <xsl:param name="imaginary" as="xs:double"/>
>    <xsl:sequence select="map{ 0:$real, 1:$imaginary }"/>
>  </xsl:function>
>
>  <xsl:function name="f:real"
>                as="xs:double" visibility="public">
>    <xsl:param name="complex" as="map(xs:integer, xs:double)"/>
>    <xsl:sequence select="$complex(0)"/>
>  </xsl:function>
>
>  <xsl:function name="f:imag"
>                as="xs:double" visibility="public">
>    <xsl:param name="complex" as="map(xs:integer, xs:double)"/>
>    <xsl:sequence select="$complex(1)"/>
>  </xsl:function>
>
>  <xsl:function name="f:add"
>                as="map(xs:integer, xs:double)" visibility="public">
>    <xsl:param name="x" as="map(xs:integer, xs:double)"/>
>    <xsl:param name="y" as="map(xs:integer, xs:double)"/>
>    <xsl:sequence select="
>         f:complex-number(
>           f:real($x) + f:real($y),
>           f:imag($x) + f:imag($y)"/>
>  </xsl:function>
>
>  <xsl:function name="f:multiply"
>                as="map(xs:integer, xs:double)" visibility="public">
>    <xsl:param name="x" as="map(xs:integer, xs:double)"/>
>    <xsl:param name="y" as="map(xs:integer, xs:double)"/>
>    <xsl:sequence select="
>         f:complex-number(
>           f:real($x)*f:real($y) - f:imag($x)*f:imag($y),
>           f:real($x)*f:imag($y) + f:imag($x)*f:real($y))"/>
>  </xsl:function>
>
>  <!-- etc. -->
> </xsl:package>
>
> When I run Saxon 9.6 on using-package.xsl, I get these error messages:
>
> Saxon-EE 9.6.0.1J from Saxonica
> Java version 1.7.0_51
> Using license serial number Vxxxxxxxxxxxxxxx
>
> Error at xsl:use-package on line 6 column 47 of marrowtr.xsl:
>  XTSE3000: Package complex-arithmetic was not found
>
> Error at xsl:variable on line 9 column 101 of marrowtr.xsl:
>  XPST0017 XPath syntax error at char 0 on line 9 in {f:complex-number(1, 0)}:
>    Cannot find a matching 2-argument function named
>  {http://example.org/complex-arithmetic.xsl}complex-number()
>
> Stylesheet compilation failed: 2 errors reported
>
>
> What should I do in order to make this simple example run as expected?
>
> It is not clear to me how finding a package given its name works -- I
> also tried importing complex-arithmetic.xsl into using-package.xsl,
> but got this error:
>
> "Error at xsl:import on line 8 column 46 of marrowtr.xsl:
>  XTSE0165: Included document complex-arithmetic.xsl is not a stylesheet"
>
>
> Any guidance how to produce a running example is enormously appreciated.
>
>
> --
> Cheers,
> Dimitre Novatchev
>
> ------------------------------------------------------------------------------
> Comprehensive Server Monitoring with Site24x7.
> Monitor 10 servers for $9/Month.
> Get alerted through email, SMS, voice calls or mobile push notifications.
> Take corrective actions from your mobile device.
> http://p.sf.net/sfu/Zoho
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help 


------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|

Re: How to make a simple running example using packages?

Dimitre Novatchev
Thank you, Dr. Kay,

It almost worked from the command line, but this time I got:

C:\xml\XSLT3.0>"C:\Program Files\Java\jre7\bin\java.exe" -Xms1024M
-Xmx1024M  -jar C:\xml\Parsers\Saxon\Ver.9.6\saxon9ee.jar  -t
-repeat:1  t.xml  using-package.xsl;complex-arithmetic.xsl

Saxon-EE 9.6.0.1J from Saxonica
Java version 1.7.0_51
Using license serial number Vxxxxxxxxxxxxxx
Generating byte code...
java.lang.NullPointerException
        at net.sf.saxon.trans.PackageLibrary.getPackage(PackageLibrary.java:75)
        at com.saxonica.ee.packages.StylesheetPackageEE.spliceUsedPackage(StylesheetPackageEE.java:61)
        at com.saxonica.ee.packages.StylesheetPackageEE.spliceUsePackages(StylesheetPackageEE.java:43)
        at net.sf.saxon.style.StylesheetPackage.preprocess(StylesheetPackage.java:371)
        at net.sf.saxon.style.Compilation.compilePackage(Compilation.java:180)
        at net.sf.saxon.s9api.XsltCompiler.compilePackage(XsltCompiler.java:394)
        at net.sf.saxon.s9api.XsltCompiler.compilePackages(XsltCompiler.java:447)
        at net.sf.saxon.Transform.doTransform(Transform.java:582)
        at net.sf.saxon.Transform.main(Transform.java:80)
Fatal error during transformation: java.lang.NullPointerException:  (no message)

Cheers,
Dimitre

On Sat, Oct 18, 2014 at 4:58 PM, Michael Kay <[hidden email]> wrote:

> If you are running from the command line, it is possible to load multiple packages by providing a semicolon-separated list of filenames in the -xsl parameter. However, I don't think this is well documented or tested and it may have restrictions concerning the order of packages.
>
> What is documented and tested is using packages via the s9api XsltCompiler interface; essentially you can compile a package into a CompiledPackage object, and then make this available to an XsltCompiler using an importPackage method.
>
> This is a bit of a stopgap; packages are work in progress. We're thinking about "classpath-like" mechanisms for the longer term.
>
> Michael Kay
> Saxonica
> [hidden email]
> +44 (0) 118 946 5893
>
>
>
>
> On 19 Oct 2014, at 00:46, Dimitre Novatchev <[hidden email]> wrote:
>
>> Hi,
>>
>> Using the trial version of Saxon 9.6EE and the example package from
>> the latest XSLT 3.0 Last Call, I am trying to produce a simple,
>> running example:
>>
>> using-package.xsl:
>> ==============
>> <xsl:package name="http://example.org/complex-arithmetic.xsl"
>>  package-version="1.0"  version="3.0"
>>  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>>  xmlns:xs="http://www.w3.org/2001/XMLSchema"
>>  xmlns:f="http://example.org/complex-arithmetic.xsl">
>>  <xsl:use-package name="complex-arithmetic"/>
>>
>>  <xsl:template match="/">
>>    <xsl:variable name="vComplex1" select="f:complex-number(1, 0)"
>> as="map(xs:integer, xs:double)"/>
>>    Real:      <xsl:sequence select="$vComplex1(0)"/>
>>    Imaginary: <xsl:sequence select="$vComplex1(1)"/>
>>  </xsl:template>
>> </xsl:package>
>>
>>
>>
>> complex-arithmetic.xsl:
>> =================
>> <xsl:package name="complex-arithmetic"
>>  package-version="1.0"  version="3.0"
>>  xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
>>  xmlns:xs="http://www.w3.org/2001/XMLSchema"
>>  xmlns:f="http://example.org/complex-arithmetic.xsl">
>>
>>  <xsl:function name="f:complex-number"
>>                as="map(xs:integer, xs:double)" visibility="public">
>>    <xsl:param name="real" as="xs:double"/>
>>    <xsl:param name="imaginary" as="xs:double"/>
>>    <xsl:sequence select="map{ 0:$real, 1:$imaginary }"/>
>>  </xsl:function>
>>
>>  <xsl:function name="f:real"
>>                as="xs:double" visibility="public">
>>    <xsl:param name="complex" as="map(xs:integer, xs:double)"/>
>>    <xsl:sequence select="$complex(0)"/>
>>  </xsl:function>
>>
>>  <xsl:function name="f:imag"
>>                as="xs:double" visibility="public">
>>    <xsl:param name="complex" as="map(xs:integer, xs:double)"/>
>>    <xsl:sequence select="$complex(1)"/>
>>  </xsl:function>
>>
>>  <xsl:function name="f:add"
>>                as="map(xs:integer, xs:double)" visibility="public">
>>    <xsl:param name="x" as="map(xs:integer, xs:double)"/>
>>    <xsl:param name="y" as="map(xs:integer, xs:double)"/>
>>    <xsl:sequence select="
>>         f:complex-number(
>>           f:real($x) + f:real($y),
>>           f:imag($x) + f:imag($y)"/>
>>  </xsl:function>
>>
>>  <xsl:function name="f:multiply"
>>                as="map(xs:integer, xs:double)" visibility="public">
>>    <xsl:param name="x" as="map(xs:integer, xs:double)"/>
>>    <xsl:param name="y" as="map(xs:integer, xs:double)"/>
>>    <xsl:sequence select="
>>         f:complex-number(
>>           f:real($x)*f:real($y) - f:imag($x)*f:imag($y),
>>           f:real($x)*f:imag($y) + f:imag($x)*f:real($y))"/>
>>  </xsl:function>
>>
>>  <!-- etc. -->
>> </xsl:package>
>>
>> When I run Saxon 9.6 on using-package.xsl, I get these error messages:
>>
>> Saxon-EE 9.6.0.1J from Saxonica
>> Java version 1.7.0_51
>> Using license serial number Vxxxxxxxxxxxxxxx
>>
>> Error at xsl:use-package on line 6 column 47 of marrowtr.xsl:
>>  XTSE3000: Package complex-arithmetic was not found
>>
>> Error at xsl:variable on line 9 column 101 of marrowtr.xsl:
>>  XPST0017 XPath syntax error at char 0 on line 9 in {f:complex-number(1, 0)}:
>>    Cannot find a matching 2-argument function named
>>  {http://example.org/complex-arithmetic.xsl}complex-number()
>>
>> Stylesheet compilation failed: 2 errors reported
>>
>>
>> What should I do in order to make this simple example run as expected?
>>
>> It is not clear to me how finding a package given its name works -- I
>> also tried importing complex-arithmetic.xsl into using-package.xsl,
>> but got this error:
>>
>> "Error at xsl:import on line 8 column 46 of marrowtr.xsl:
>>  XTSE0165: Included document complex-arithmetic.xsl is not a stylesheet"
>>
>>
>> Any guidance how to produce a running example is enormously appreciated.
>>
>>
>> --
>> Cheers,
>> Dimitre Novatchev
>>
>> ------------------------------------------------------------------------------
>> Comprehensive Server Monitoring with Site24x7.
>> Monitor 10 servers for $9/Month.
>> Get alerted through email, SMS, voice calls or mobile push notifications.
>> Take corrective actions from your mobile device.
>> http://p.sf.net/sfu/Zoho
>> _______________________________________________
>> saxon-help mailing list archived at http://saxon.markmail.org/
>> [hidden email]
>> https://lists.sourceforge.net/lists/listinfo/saxon-help
>

------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|

Re: [xsl] Re: How to make a simple running example using packages?

John Lumley-2
In reply to this post by Michael Kay
On 19/10/2014 01:37, Dimitre Novatchev [hidden email] wrote:
> C:\xml\XSLT3.0>"C:\Program Files\Java\jre7\bin\java.exe" -Xms1024M
> -Xmx1024M  -jar C:\xml\Parsers\Saxon\Ver.9.6\saxon9ee.jar  -t
> -repeat:1  t.xml  using-package.xsl;complex-arithmetic.xsl
Dimitre,

This is now resolved. See https://saxonica.plan.io/issues/2190.
Basically the steps are:

 1. add |package-version=".*"| to any |xsl:use-package| lacking that
    attribute.
 2. make the principal stylesheet the *last* in the semicolon-separated
    list of stylesheet/packages, rather than the first as given in
    current documentation. This ensures the principal stylesheet is
    compiled last after all possible packages.

For your example the order of the packages doesn't matter (I've checked
it running with either order), but in cases where there may be packages
that are unused, placing the principal stylesheet last will help for the
moment. Note the next maintenance release will support default package
version requests, as well as comforming to the package-version syntax of
the specification, though complex dependency orders may not be supported.

Thanks for raising this, even if it's in the 'experimental wing'

John



--
*John Lumley* MA PhD CEng FIEE
[hidden email] <mailto:[hidden email]>
on behalf of Saxonica Ltd

------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help 
Reply | Threaded
Open this post in threaded view
|

Re: [xsl] Re: How to make a simple running example using packages?

Dimitre Novatchev
Thank you John,

Now the example works!

Cheers,
Dimitre

On Mon, Oct 20, 2014 at 2:59 AM, John Lumley <[hidden email]> wrote:

> On 19/10/2014 01:37, Dimitre Novatchev [hidden email] wrote:
>> C:\xml\XSLT3.0>"C:\Program Files\Java\jre7\bin\java.exe" -Xms1024M
>> -Xmx1024M  -jar C:\xml\Parsers\Saxon\Ver.9.6\saxon9ee.jar  -t
>> -repeat:1  t.xml  using-package.xsl;complex-arithmetic.xsl
> Dimitre,
>
> This is now resolved. See https://saxonica.plan.io/issues/2190.
> Basically the steps are:
>
>  1. add |package-version=".*"| to any |xsl:use-package| lacking that
>     attribute.
>  2. make the principal stylesheet the *last* in the semicolon-separated
>     list of stylesheet/packages, rather than the first as given in
>     current documentation. This ensures the principal stylesheet is
>     compiled last after all possible packages.
>
> For your example the order of the packages doesn't matter (I've checked
> it running with either order), but in cases where there may be packages
> that are unused, placing the principal stylesheet last will help for the
> moment. Note the next maintenance release will support default package
> version requests, as well as comforming to the package-version syntax of
> the specification, though complex dependency orders may not be supported.
>
> Thanks for raising this, even if it's in the 'experimental wing'
>
> John
>
>
>
> --
> *John Lumley* MA PhD CEng FIEE
> [hidden email] <mailto:[hidden email]>
> on behalf of Saxonica Ltd
>
> ------------------------------------------------------------------------------
> Comprehensive Server Monitoring with Site24x7.
> Monitor 10 servers for $9/Month.
> Get alerted through email, SMS, voice calls or mobile push notifications.
> Take corrective actions from your mobile device.
> http://p.sf.net/sfu/Zoho
> _______________________________________________
> saxon-help mailing list archived at http://saxon.markmail.org/
> [hidden email]
> https://lists.sourceforge.net/lists/listinfo/saxon-help

------------------------------------------------------------------------------
Comprehensive Server Monitoring with Site24x7.
Monitor 10 servers for $9/Month.
Get alerted through email, SMS, voice calls or mobile push notifications.
Take corrective actions from your mobile device.
http://p.sf.net/sfu/Zoho
_______________________________________________
saxon-help mailing list archived at http://saxon.markmail.org/
[hidden email]
https://lists.sourceforge.net/lists/listinfo/saxon-help