xsl-list
[Top] [All Lists]

RE: [xsl] Confusing trace from Saxon HE9

2009-12-08 18:17:37
Well, it says the error is on line 204 calling generate-id(), and line 204
has a call to generate-id($node), so it's fairly clear that $node contains a
sequence of two p elements.

Next thing I notice is that <xsl:param name="node"/> doesn't declare the
expected type. If you want good diagnostics, always declare the types of
your variables and (especially) parameters.

The call stack is misleading because of tail-call optimisation. In Saxon,
when the last thing that a template does is to call another template, then
instead of doing the call and then returning, the return is done first, and
then the call. This reduces the use of stack space which can make a very big
difference to highly recursive code, and is therefore a common technique in
functional languages. You've got quite a few tail calls in this stylesheet
and the stack trace basically skips over them because the calls aren't
present on the stack.

Because we know we're processing the div1 it looks likely that $node has
been passed into the match="div1" template and then into the
name="div0fragment" template; in turn it comes from the match="div0" and
from match="body[div0]" on line 67. At that point the stacktrace shows we're
coming in from a different stylesheet module, which appears to be where the
value of $node is first supplied, so there my debugging has to stop.

I think you will find that if you declare the types of the template
parameters the error will be detected much earlier, and therefore with
diagnostics that get you much closer to the real cause.

The other thing you could try is running with the -T (tracing) option. One
side-effect of this is to suppress tail-call optimization, which makes both
the tracing and any stack-dump output more meaningful in terms of your
original source code.

Regards,

Michael Kay
http://www.saxonica.com/
http://twitter.com/michaelhkay 

-----Original Message-----
From: Jeroen Hellingman [mailto:jeroen(_at_)bohol(_dot_)ph] 
Sent: 08 December 2009 19:59
To: xsl-list(_at_)lists(_dot_)mulberrytech(_dot_)com
Subject: [xsl] Confusing trace from Saxon HE9


I am working with a rather complex stylesheet to split a TEI 
document into pieces for an epub file, and get the following 
trace on an error.

Error on line 204 of splitter.xsl:
  XPTY0004: A sequence of more than one item is not allowed 
as the first argument of
  generate-id() (<p/>, <p/>)
  at xsl:call-template name="content.div1" 
(file:/C:/Users/Jeroen/Documents/eLibrary/Tools/tei2html/split
ter.xsl#180)
  at xsl:apply-templates
(file:/C:/Users/Jeroen/Documents/eLibrary/Tools/tei2html/split
ter.xsl#94)
     processing /TEI.2/text[1]/body[1]/div0[1]/div1[1]
  at xsl:apply-templates
(file:/C:/Users/Jeroen/Documents/eLibrary/Tools/tei2html/split
ter.xsl#71)
     processing /TEI.2/text[1]/body[1]/div0[1]
  at xsl:apply-templates
(file:/C:/Users/Jeroen/Documents/eLibrary/Tools/tei2html/split
ter.xsl#41)
     processing /TEI.2/text[1]/body[1]
  at xsl:apply-templates
(file:/C:/Users/Jeroen/Documents/eLibrary/Tools/tei2html/heade
r.xsl#47)
     processing /TEI.2/text[1]
  at xsl:apply-templates
(file:/C:/Users/Jeroen/Documents/eLibrary/Tools/tei2html/tei2e
pub.xsl#88)
     processing /TEI.2
Transformation failed: Run-time errors were reported

The thing that is confusing me is that line 204 in my 
stylesheet is not called from the template "content.div1" 
mentioned on the line before.

Can you give me a hint on how to interpret this trace, as I 
do not understand how a

<xsl:call-template name="content.div1"/>

brings me into a template

<xsl:template name="filename.div0fragment">

Furthermore, the failing template receives two nodes in a 
variable that I hardly expect to be grouped together. In the 
source document they are not even siblings.


The full stylesheet in question is here:  
http://code.google.com/p/tei2html/source/browse/trunk/splitter.xsl

The document it is fed (via another top-level stylesheet, 
tei2epub.xsl) is here: 
http://code.google.com/p/tei2html/source/browse/trunk/test.xml

The offending lines in the input document causing the issue 
is at lines
104-111:

<q rend="block"><text><body><div1><head>Section head in 
quoted material</head>

<p>This is a paragraph in quoted material<note>This is a 
footnote in quoted material.</note> This paragraph contains a 
footnote, to verify correct handling of this convoluted 
situation during the transformation.</p> </div1></body></text></q>


<p>Books created with these stylesheet include: ....</p>



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