On Mar 25, 2008, at 7:24 AM, Michael Kay wrote:

The answer is that in general it's possible, but it's the responsibility of the implementor of the extension element to make sure that all the objects used in the compiled representation are Serializable.
If it fails, then I would normally expect it to fail when compiling, not when running.

I'm not sure I understand your comment.  The stylesheet runs with no problem when it is not compiled using net.sf.saxon.Compile, but fails when it is compiled.  The two runs were conducted using the same classpath, same stylesheet source, same source document and same parameters - the only difference is the compilation of the stylesheet.  Can you help me understand where serialization comes into the picture?

Normally element-available() takes a string literal as its argument, and in that case it's evaluated at compile time. I'm therefore surprised that it should cause a run-time failure.
I think you'll need to send me some code that I can look at more carefully.

Here's the stylesheet itself:

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
extension-element-prefixes="tamc" >
<!-- -->
<xsl:param name="maxImageWidth" >600</xsl:param>
<xsl:param name="maxImageHeight" >600</xsl:param>
<xsl:param name="contentPath" />
<!-- -->
<xsl:output name="content-format" method="xhtml" indent="no" encoding="UTF-8"
doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN"
<!-- -->
<xsl:strip-space elements="dtbook:* *"/>
<!-- -->
<xsl:template match="/">
<!-- Make sure our extension elements are available -->
<xsl:if test="element-available('tamc:constructImageElementWithValidation')">
<xsl:message terminate="no">constructImageElementWithValidation extension element ***IS*** available</xsl:message>
<xsl:if test="not(element-available('tamc:constructImageElementWithValidation'))">
<xsl:message terminate="yes">constructImageElementWithValidation extension element ***IS NOT*** available</xsl:message>
<xsl:apply-templates />
<!-- -->
<xsl:template match="dtbook:img">
<xsl:message terminate="no">Calling constructImageElementWithValidation on image <xsl:value-of select="@src" />, width <xsl:value-of select="@width" /> x height <xsl:value-of select="@height" /></xsl:message>
  <tamc:constructImageElementWithValidation src="{@src}" alt="{@alt}" width="{@width}" height="{@height}" class="{@class}" id="{@id}"
          maxImageWidth="{$maxImageWidth}" maxImageHeight="{$maxImageHeight}" contentPath="{$contentPath}" />
<!-- -->

Here's the script I used to invoke the non-compiled version:

java -cp /Users/cvonsee/devtools/saxonb9-0-0-2j/saxon9.jar:/Users/cvonsee/myworkspace/AccessibleMediaCenter/webapps/accessiblemediacenter/WEB-INF/classes net.sf.saxon.Transform  -o:"/Users/cvonsee/temp/saxon test/outputStandalone.xml" -xsl:"/Users/cvonsee/temp/saxon test/ss.xsl"  "/Network/Servers/salmon/data3/CAST NIMAS Exemplars/Exemplar 6/NIMAS Exemplar6 - Science - Baseline 1.1 Folder/NIMASExemplar6Science.xml"  contentPath="/Network/Servers/salmon/data3/CAST NIMAS Exemplars/Exemplar 6/NIMAS Exemplar6 - Science - Baseline 1.1 Folder"  

Here's output from the non-compiled version:

constructImageElementWithValidation extension element ***IS*** available
Calling constructImageElementWithValidation on image ./images/U01C02/p011-001.jpg, width  x height 
Calling constructImageElementWithValidation on image ./images/U01C02/p012-001.jpg, width  x height 
<snip more messages from template>

Here's the script I used to invoke the compiled version:

java -cp /Users/cvonsee/devtools/saxonb9-0-0-2j/saxon9.jar net.sf.saxon.Compile ss.xsl ss.sxx
java -cp /Users/cvonsee/devtools/saxonb9-0-0-2j/saxon9.jar:/Users/cvonsee/myworkspace/AccessibleMediaCenter/webapps/accessiblemediacenter/WEB-INF/classes net.sf.saxon.Transform  -o:"/Users/cvonsee/temp/saxon test/outputStandalone.xml" -c:"/Users/cvonsee/temp/saxon test/ss.sxx"  "/Network/Servers/salmon/data3/CAST NIMAS Exemplars/Exemplar 6/NIMAS Exemplar6 - Science - Baseline 1.1 Folder/NIMASExemplar6Science.xml"  contentPath="/Network/Servers/salmon/data3/CAST NIMAS Exemplars/Exemplar 6/NIMAS Exemplar6 - Science - Baseline 1.1 Folder"  

Here's the output from the script used to invoke the compiled version:

Serializing compiled stylesheet
Finished serializing stylesheet
constructImageElementWithValidation extension element ***IS NOT*** available
Processing terminated by xsl:message at line 29 in ss.xsl

Let me know if you need more info.


Begin forwarded message:

From: Chris von See <chris@techadapt.com>
Date: March 21, 2008 8:53:24 AM PDT
To: Chris von See <chris@techadapt.com>
Subject: Saxon extension elements not executed with precompiled stylesheet?

Hi -

Using Saxon-B for Java and JDK 1.5.04, I wrote a Saxon extension element which is called correctly when the stylesheet is invoked using the -xsl: option on the command line. However, when I compile that same stylesheet and run it from the command line using the -c option I get an error (generated by evaluating element-available() in the stylesheet) indicating that the extension element is not available. In both cases the classpath is the same, and the only change is the use of the compiled stylesheet and the -c vs -xsl option. Can Saxon call extension elements from precompiled stylesheets?

Chris von See
TechAdapt, Inc.