Project

Profile

Help

I find it surprising that the initial template is called without a context node

Added by Eric van der Vlist about 7 years ago

When you know it you can set the context node using ixsl:page() or whatever but I haven't seen it mentioned in the doc (have I read it to fact?) and it took me some time to understand what the error messages I had were really meaning.

I think that this deserves a special mention in the documentation!

Thanks,

Eric

PS: BTW, is there any reason why the context node couldn't be, for instance, the root of the page?


Replies (4)

Please register to reply

RE: I find it surprising that the initial template is called without a context node - Added by Michael Kay about 7 years ago

Could you explain what invocation syntax you are using for the transformation?

RE: I find it surprising that the initial template is called without a context node - Added by Eric van der Vlist about 7 years ago

I am using the following invocation :

        <script type="text/javascript" language="javascript" src="saxon/SaxonceDebug/Saxonce.nocache.js"></script>
    <script type="application/xslt+xml" language="xslt2.0" src="hello-world-mvc-codemirror.xsl" data-initial-template="init"></script>

The following error:

SaxonCE.XSLT20Processor 00:19:49.853
SEVERE: XPathException in invokeTransform: Finding root of tree: the context item is undefined 

happens in the named template "init" when I used a variable defined as:


The example in which I have the issue is not trivial and if you think that this is a bug I can try to reduce it to something simpler.

Thanks,

Eric

RE: I find it surprising that the initial template is called without a context node - Added by Michael Kay about 7 years ago

This is the way it's designed.

I'm reluctant to make the HTML document be the initial context node; this would encourage use of global variables bound to nodes in the HTML page, which is best avoided because global variables retain their values over multiple transformation phases but the HTML document is mutable between phases. (There's a messy area here which needs to be much better specified.)

The natural reading of the XSLT 2.0 rules for initiating a transformation are that if you don't define an initial context node, then there isn't one.

RE: I find it surprising that the initial template is called without a context node - Added by Eric van der Vlist about 7 years ago

Thanks, now I understand better this feature.

My main point was about the documentation, though.

The fact that there is no initial context node is kind of implicit when I re-read this "snippet":http://saxonica.com/ce/user-doc/1.1/index.html#!starting/running/xsltscript:

bq. Assuming that data-source is supplied, execution proceeds as follows. When the page is loaded, the Saxon stub will be executed, the source document will be fetched, the stylesheet will be compiled, and the stylesheet will be invoked with the source document as its principal input (initial context node). So the <xsl:template match="/"> template will be invoked in the usual way.

My point was that a paragraph explicitly explaining what happens when there is no data-source would be useful.

Thanks,

Eric

    (1-4/4)

    Please register to reply