https://saxonica.plan.io/https://saxonica.plan.io/favicon.ico2012-03-22T16:48:09ZSaxonica Developer CommunitySaxon-CE - Bug #1445: xsl:result-document href-attribute: ?select=//div[1] and alike result in ClassCastExceptionhttps://saxonica.plan.io/issues/1445?journal_id=12922012-03-22T16:48:09ZCommunity Adminsupport@saxonica.com
<ul><li><strong>Assignee</strong> set to <i>Philip Fearon</i></li></ul><p>I'm afraid I'm still unable to reproduce this issue with the ClassCastException. If this were simply a problem related to the href of xsl:result-document, I wouldn't expect to see the error you're getting. The exception you're seing is only being handled at the top level, so I can't event tell whether this is a static (compile-time) or dynamic error.</p>
<p>My suspicion is that the exception occurs at run-time during the attempt to update the HTML DOM, but that's a bit of a wild guess until I have some more information.</p>
<p>Could you please send a simple example that reproduces this issue, either as an attachment on this issue thread or direct to myself at: <a href="mailto:phil@saxonica.com" class="email">phil@saxonica.com</a></p> Saxon-CE - Bug #1445: xsl:result-document href-attribute: ?select=//div[1] and alike result in ClassCastExceptionhttps://saxonica.plan.io/issues/1445?journal_id=13262012-03-23T14:56:59ZPhilip Fearonpgfearo@gmail.com
<ul><li><strong>File</strong> <a href="/attachments/111">test-ce.html</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/111/test-ce.html">test-ce.html</a> added</li><li><strong>File</strong> <a href="/attachments/112">test-ce.xsl</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/112/test-ce.xsl">test-ce.xsl</a> added</li></ul><p>Looking at the included sample files the main problem here is that</p>
<p>there is an issue with the approach used in the XSLT and the resulting</p>
<p>error message is extremely unhelpful.</p>
<p>In the provided sample HTML page, the <script> element has a</p>
<p>data-source attribute value set to a URL that happens to be the same</p>
<p>as the host HTML page, which happens to be well-formed XML.</p>
<p>So, this file is loaded as XML by Saxon-CE using the usual</p>
<p>XMLHTTPRequest object and the XSLT transform commences on this file.</p>
<p>The issue is that when processing the href attribute of the</p>
<p>xsl:result-document document, the baseURI of the context node and that</p>
<p>of the document object are compared. Because these are found to be</p>
<p>equal, Saxon-CE wrongly assumes that the context node is within the</p>
<p>DOM and attempts to proceed with modifying some part of the context</p>
<p>node instead of the DOM.</p>
<p>To prevent this from happening in future Saxon-CE releases I'll add a</p>
<p>check on the data-source attribute in the <script> element, if the URL</p>
<p>is the same as that of the host page a fatal error will be raised.</p>
<p>To acheive the same effect as the supplied sample the following</p>
<p>changes could be made to the two sample files:</p>
<ol>
<li>HTML File</li>
</ol>
<hr>
<p>1.1. Remove the data-source attribute from the <script> element</p>
<p>1.2. Add a data-initial-template attribute with value 'main' to the</p>
<script> element
2. XSLT File
---------
2.1. Remove the match="/" attribute from the entry template and add a
name="main" attribute instead
2.2. Modify the select="*" attribute in the apply-templates
instruction (within the entry template) to be select="ixsl:page()/*"
These modified sample files are attached.
The key part to this approach is the ixsl:page() extension function.
This returns the document node of the host HTML page, so ixsl:page()/*
will return the html element, apply-templates can then be called on
this so that HTML child elements can be processed. In this case,
because the context node is always part of the DOM (which is
read/write) it can be exploited safely in result-document href
attributes.
It's likely of course that there'll be other cases where you need to
use xsl:result-document but when the context node is from an XML file
(specified in the data-source). In this case, you can either:
i) use an absolute location in your href XPath (e.g. //div/p[@class='new']) or
2) wrap the result-document instruction within an xsl:for-each
instruction where the ixsl:page() function is used in the select
attribute to set the context, (eg. Saxon-CE - Bug #1445: xsl:result-document href-attribute: ?select=//div[1] and alike result in ClassCastExceptionhttps://saxonica.plan.io/issues/1445?journal_id=13272012-03-23T14:57:10ZPhilip Fearonpgfearo@gmail.com
<ul><li><strong>Status</strong> changed from <i>New</i> to <i>Resolved</i></li></ul> Saxon-CE - Bug #1445: xsl:result-document href-attribute: ?select=//div[1] and alike result in ClassCastExceptionhttps://saxonica.plan.io/issues/1445?journal_id=14122012-04-23T08:50:51ZPhilip Fearonpgfearo@gmail.com
<ul><li><strong>Fixed in version</strong> set to <i>Beta 0.2</i></li></ul> Saxon-CE - Bug #1445: xsl:result-document href-attribute: ?select=//div[1] and alike result in ClassCastExceptionhttps://saxonica.plan.io/issues/1445?journal_id=14302012-04-23T09:03:29ZPhilip Fearonpgfearo@gmail.com
<ul><li><strong>Sprint/Milestone</strong> set to <i>Beta 0.2</i></li></ul> Saxon-CE - Bug #1445: xsl:result-document href-attribute: ?select=//div[1] and alike result in ClassCastExceptionhttps://saxonica.plan.io/issues/1445?journal_id=20522013-02-22T09:47:46ZO'Neil Delprattoneil@saxonica.com
<ul><li><strong>Status</strong> changed from <i>Resolved</i> to <i>Closed</i></li><li><strong>Fixed in version</strong> changed from <i>Beta 0.2</i> to <i>1.0</i></li></ul><p>Fixed in Saxon-CE version 1.0</p> Saxon-CE - Bug #1445: xsl:result-document href-attribute: ?select=//div[1] and alike result in ClassCastExceptionhttps://saxonica.plan.io/issues/1445?journal_id=20752013-02-22T09:57:27ZO'Neil Delprattoneil@saxonica.com
<ul><li><strong>Sprint/Milestone</strong> changed from <i>Beta 0.2</i> to <i>Release 1.0</i></li><li><strong>% Done</strong> changed from <i>0</i> to <i>100</i></li></ul>