@@ -139,28 +139,24 @@ public void endDocument() {
139
139
}
140
140
141
141
public void addSubtree (XdmNode node ) {
142
- try {
143
- receiver .append (node .getUnderlyingNode ());
144
- } catch (UnsupportedOperationException use ) {
145
- // Do it the hard way
146
- if (node .getNodeKind () == XdmNodeKind .DOCUMENT ) {
147
- writeChildren (node );
148
- } else if (node .getNodeKind () == XdmNodeKind .ELEMENT ) {
149
- addStartElement (node );
150
- writeChildren (node );
151
- addEndElement ();
152
- } else if (node .getNodeKind () == XdmNodeKind .COMMENT ) {
153
- addComment (node .getStringValue ());
154
- } else if (node .getNodeKind () == XdmNodeKind .TEXT ) {
155
- addText (node .getStringValue ());
156
- } else if (node .getNodeKind () == XdmNodeKind .PROCESSING_INSTRUCTION ) {
157
- addPI (node .getNodeName ().getLocalName (), node .getStringValue ());
158
- } else {
159
- throw new UnsupportedOperationException ("Unexpected node type" );
160
- }
161
- } catch (XPathException xpe ) {
162
- throw new XProcException (xpe );
163
- }
142
+ // N.B. It's tempting to copy the node with
143
+ // receiver.append(node.getUnderlyingNode());
144
+ // but that doesn't work: https://saxonica.plan.io/issues/5691
145
+
146
+ if (node .getNodeKind () == XdmNodeKind .DOCUMENT ) {
147
+ writeChildren (node );
148
+ } else if (node .getNodeKind () == XdmNodeKind .ELEMENT ) {
149
+ addStartElement (node );
150
+ writeChildren (node );
151
+ addEndElement ();
152
+ } else if (node .getNodeKind () == XdmNodeKind .COMMENT ) {
153
+ addComment (node .getStringValue ());
154
+ } else if (node .getNodeKind () == XdmNodeKind .TEXT ) {
155
+ addText (node .getStringValue ());
156
+ } else if (node .getNodeKind () == XdmNodeKind .PROCESSING_INSTRUCTION ) {
157
+ addPI (node .getNodeName ().getLocalName (), node .getStringValue ());
158
+ } else {
159
+ throw new UnsupportedOperationException ("Unexpected node type" ); }
164
160
}
165
161
166
162
protected void writeChildren (XdmNode node ) {
@@ -336,11 +332,24 @@ public void addText(String text) {
336
332
}
337
333
338
334
public void addPI (String target , String data ) {
335
+ addPI (target , data , VoidLocation .instance ());
336
+ }
337
+
338
+ public void addPI (String target , String data , Location location ) {
339
339
try {
340
- receiver .processingInstruction (target , data , VoidLocation . instance () , 0 );
340
+ receiver .processingInstruction (target , data , location , 0 );
341
341
} catch (XPathException e ) {
342
342
throw new XProcException (e );
343
343
}
344
344
}
345
+
346
+ public void addPI (XdmNode node ) {
347
+ Location location = VoidLocation .instance ();
348
+ if (node .getBaseURI () != null ) {
349
+ location = new SysIdLocation (node .getBaseURI ().toString ());
350
+ receiver .setSystemId (node .getBaseURI ().toString ());
351
+ }
352
+ addPI (node .getNodeName ().getLocalName (), node .getStringValue (), location );
353
+ }
345
354
}
346
355
0 commit comments