https://saxonica.plan.io/https://saxonica.plan.io/favicon.ico2022-09-19T14:30:12ZSaxonica Developer CommunitySaxon - Bug #5691: Copying a processing instruction drops base URI informationhttps://saxonica.plan.io/issues/5691?journal_id=218032022-09-19T14:30:12ZNorm Tovey-Walsh
<ul><li><strong>Applies to branch</strong> <i>10, 11, trunk</i> added</li></ul> Saxon - Bug #5691: Copying a processing instruction drops base URI informationhttps://saxonica.plan.io/issues/5691?journal_id=218042022-09-19T22:04:05ZMichael Kaymike@saxonica.com
<ul></ul><p>This is a complicated area. The location passed to an Outputter is generally the location of the instruction that constructs the node, not the location of the node itself. The copy-of instruction takes special (somewhat devious) measures to ensure that the location of the node being copied is passed to the DocumentBuilder that constructs the copy of the node; in some cases (not all) the new node retains the location of the old node.</p>
<p>Also complicating this is that the location of a node isn't in all cases the same thing as its base URI.</p>
<p>Need more detail on this one before making any changes.</p> Saxon - Bug #5691: Copying a processing instruction drops base URI informationhttps://saxonica.plan.io/issues/5691?journal_id=218062022-09-20T08:11:33ZNorm Tovey-Walsh
<ul></ul><p>That's fair. Here's some context from a Slack chat:</p>
<p>Here's a weird one. I'm processing an XInclude. I construct a tree for the included content by calling various methods on the Receiver. Let's say the content I construct is <?pi ?>. The baseURI (which comes from the underlying nodes getSystemId()) for foo is fine, for ?pi? is "", and for bar is "". The presence of the PI makes the following element(s) not have a base URI. I thought this was caused by my failure to supply a base URI for the PI. But I've changed the code so that I do this:</p>
<pre><code> public void addPI(XdmNode node) {
Location location = VoidLocation.instance();
if (node.getBaseURI() != null) {
location = new SysIdLocation(node.getBaseURI().toString());
receiver.setSystemId(node.getBaseURI().toString());
}
addPI(node.getNodeName().getLocalName(), node.getStringValue(), location);
}
</code></pre>
<p>where the 3 argument form of addPI is:</p>
<pre><code> public void addPI(String target, String data, Location location) {
try {
receiver.processingInstruction(target, StringView.of(data), location, 0);
} catch (XPathException e) {
throw new XProcException(e);
}
}
</code></pre>
<p>The original PI that I'm effectively copying does have a base URI so the SysIdLocation is correct and is being passed to the receiver.</p>
<p>It looks like <code>decompose()</code> in <code>ComplexContentOutputter</code> is copying the PI again and passing a null location, because append in <code>Outputter</code> passes <code>Loc.NONE</code>.</p>
<p>I confess, I don't see where the PI comes into it. It would make more sense if all the elements lost their base URIs.</p>
<p>I'll see if I can extract out a test case.</p> Saxon - Bug #5691: Copying a processing instruction drops base URI informationhttps://saxonica.plan.io/issues/5691?journal_id=218072022-09-20T08:58:22ZNorm Tovey-Walsh
<ul><li><strong>File</strong> <a href="/attachments/58722">iss5691.zip</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/58722/iss5691.zip">iss5691.zip</a> added</li></ul><p>The attached test case demonstrates the problem. (I've done no more to investigate it beyond reproducing it.)</p>
<p>If you run the main class, it will print:</p>
<pre><code>module: file:/Volumes/Saxonica/src/saxonica/test-apps/iss5691/main.xml: file:/Volumes/Saxonica/src/saxonica/test-apps/iss5691/main.xml
foo: file:/Volumes/Saxonica/src/saxonica/test-apps/iss5691/main.xml: file:/Volumes/Saxonica/src/saxonica/test-apps/iss5691/main.xml
pi: :
bar: :
</code></pre>
<p>For some reason, appending the inner module document loses all base URIs starting at the first PI.</p> Saxon - Bug #5691: Copying a processing instruction drops base URI informationhttps://saxonica.plan.io/issues/5691?journal_id=222452022-12-13T14:54:51ZMichael Kaymike@saxonica.com
<ul></ul><p>The bug appears to be something like this: when a tree with no known base URI is copied to a tree builder for which a base URI (system ID) has been set, copying element nodes to the tree causes them to acquire the base URI that was set for the tree builder. However, copying processing instruction nodes causes the corresponding nodes in the result tree to have no base URI; moreover, this change persists until the next node with a known base URI is encountered.</p>
<p>The problem is in TinyBuilder line 534, when handling processing instructions:</p>
<pre><code> String localLocation = locationId.getSystemId();
tt.setSystemId(nodeNr, localLocation);
</code></pre>
<p>The corresponding code for element nodes is at line 321:</p>
<pre><code> String localSystemId = location.getSystemId();
if (isUseEventLocation() && localSystemId != null) {
tt.setSystemId(nodeNr, localSystemId);
} else if (currentDepth == 1) {
tt.setSystemId(nodeNr, systemId);
}
</code></pre>
<p>where <code>systemId</code> is the systemId property of the <code>TinyBuilder</code>.</p>
<p>I think the code for processing instructions should be the same as for elements.</p> Saxon - Bug #5691: Copying a processing instruction drops base URI informationhttps://saxonica.plan.io/issues/5691?journal_id=222462022-12-13T14:55:45ZMichael Kaymike@saxonica.com
<ul><li><strong>Subject</strong> changed from <i>Appending a node discards any location that it might have had</i> to <i>Copying a processing instruction drops base URI information</i></li><li><strong>Category</strong> set to <i>Internals</i></li><li><strong>Status</strong> changed from <i>New</i> to <i>In Progress</i></li><li><strong>Assignee</strong> set to <i>Michael Kay</i></li></ul> Saxon - Bug #5691: Copying a processing instruction drops base URI informationhttps://saxonica.plan.io/issues/5691?journal_id=222472022-12-13T15:42:24ZMichael Kaymike@saxonica.com
<ul></ul><p>The fix seems to cause no obvious regression, but I need to create a specific unit test before I'm 100% comfortable with it.</p> Saxon - Bug #5691: Copying a processing instruction drops base URI informationhttps://saxonica.plan.io/issues/5691?journal_id=222482022-12-13T18:13:47ZMichael Kaymike@saxonica.com
<ul></ul><p>While attempting to create a unit test for this (so far unsuccessfully), I hit an apparently unrelated problem with the TinyBuilder. My test does the following sequence of calls on a TinyBuilder</p>
<pre><code>open()
startDocument()
startElement(TOP)
endElement
documentNode.copy()
startElement(BOTTOM)
endElement
endDocument()
close()
</code></pre>
<p>After this sequence of calls, <code>getCurrentRoot()</code> returns the BOTTOM element, not the document node.</p>
<p>What happens here is that the documentNode.copy() operation starts with a <code>startDocument()</code> event, and ends with an <code>endDocument()</code> event. The inner <code>startDocument()</code> event is correctly ignored, but the inner <code>endDocument()</code> is not - it decrements the level number.</p>
<p>After exploring this a little, I concluded that it's not a problem because in practice the events are always sent to the <code>TinyBuilder</code> via a <code>ComplexContentOutputter</code>, which filters out the unwanted <code>startDocument()</code> and <code>endDocument()</code> events.</p> Saxon - Bug #5691: Copying a processing instruction drops base URI informationhttps://saxonica.plan.io/issues/5691?journal_id=222492022-12-14T15:35:14ZMichael Kaymike@saxonica.com
<ul><li><strong>Status</strong> changed from <i>In Progress</i> to <i>Resolved</i></li><li><strong>Priority</strong> changed from <i>Low</i> to <i>Normal</i></li><li><strong>Fix Committed on Branch</strong> <i>10, 11, trunk</i> added</li><li><strong>Platforms</strong> <i>.NET, Java</i> added</li></ul><p>Created a unit test. Fixed and tested on the 10, 11, and 12 branches.</p> Saxon - Bug #5691: Copying a processing instruction drops base URI informationhttps://saxonica.plan.io/issues/5691?journal_id=224222023-01-13T18:09:00ZCommunity Adminsupport@saxonica.com
<ul><li><strong>% Done</strong> changed from <i>0</i> to <i>100</i></li><li><strong>Fixed in Maintenance Release</strong> <i>12.0</i> added</li></ul><p>Bug issue fix applied in the Saxon 12.0 Major Release.
Leaving this bug marked as Resolved until fix applied</p> Saxon - Bug #5691: Copying a processing instruction drops base URI informationhttps://saxonica.plan.io/issues/5691?journal_id=229172023-02-08T16:24:17ZO'Neil Delprattoneil@saxonica.com
<ul><li><strong>Fixed in Maintenance Release</strong> <i>11.5</i> added</li></ul><p>Bug fix applied in the Saxon 11.5 maintenance release.</p> Saxon - Bug #5691: Copying a processing instruction drops base URI informationhttps://saxonica.plan.io/issues/5691?journal_id=230182023-02-16T16:19:59ZO'Neil Delprattoneil@saxonica.com
<ul><li><strong>Status</strong> changed from <i>Resolved</i> to <i>Closed</i></li><li><strong>Fixed in Maintenance Release</strong> <i>10.9</i> added</li></ul><p>Bug fix applied in the Saxon 10.9 maintenance release.</p>