Skip to content

Commit 9ce9b10

Browse files
committed
fn:transform - simplify path to invoke transformer
The stages of invocation of the XSLT transformer have been generalised/abstracted enough as we worked through the development that some simplification is now possible. Several cases collapse together, because of the Delivery abstraction that delivers the result in the configured form.
1 parent 8fb3281 commit 9ce9b10

File tree

1 file changed

+7
-51
lines changed

1 file changed

+7
-51
lines changed

exist-core/src/main/java/org/exist/xquery/functions/fn/FnTransform.java

Lines changed: 7 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -382,13 +382,9 @@ private MapType invokeCallFunction() throws XPathException, SaxonApiException {
382382
} else {
383383
throw new XPathException(FnTransform.this, ErrorCodes.FOXT0002, "Error - transform using XSLT 3.0 option initial-function, but the corresponding option function-params was not supplied.");
384384
}
385-
if (options.deliveryFormat == DeliveryFormat.RAW) {
386-
final Sequence existValue = Convert.ToExist.of(xslt30Transformer.callFunction(qName, functionParams));
387-
return makeResultMap(options, existValue, resultDocuments);
388-
} else {
389-
xslt30Transformer.callFunction(qName, functionParams, destination);
390-
return makeResultMap(options, delivery.getDocument(), resultDocuments);
391-
}
385+
386+
xslt30Transformer.callFunction(qName, functionParams, destination);
387+
return makeResultMap(options, delivery, resultDocuments);
392388
}
393389

394390
private MapType invokeCallTemplate() throws XPathException, SaxonApiException {
@@ -398,20 +394,14 @@ private MapType invokeCallTemplate() throws XPathException, SaxonApiException {
398394
"AND " + INITIAL_TEMPLATE.name + " supplied indicating call-template invocation.");
399395
}
400396

401-
final QName qName = options.initialTemplate.get().getQName();
402397
//TODO (AP) - Implement complete conversion in the {@link Convert} class
403398
//TODO (AP) - The saxDestination conversion loses type information in some cases
404399
//TODO (AP) - e.g. fn-transform-63 from XQTS has a <xsl:template name='main' as='xs:integer'>
405400
//TODO (AP) - which alongside "delivery-format":"raw" fails to deliver an int
406-
if (options.deliveryFormat == DeliveryFormat.RAW) {
407-
final Sequence existValue = Convert.ToExist.of(xslt30Transformer.callTemplate(Convert.ToSaxon.of(qName)));
408-
return makeResultMap(options, existValue, resultDocuments);
409-
} else {
410-
//TODO (AP) - The saxDestination conversion loses type information in some cases
411-
//TODO (AP) - e.g. fn-transform-63 from XQTS has a <xsl:template name='main' as='xs:integer'>
412-
xslt30Transformer.callTemplate(Convert.ToSaxon.of(qName), destination);
413-
return makeResultMap(options, delivery, resultDocuments);
414-
}
401+
402+
final QName qName = options.initialTemplate.get().getQName();
403+
xslt30Transformer.callTemplate(Convert.ToSaxon.of(qName), destination);
404+
return makeResultMap(options, delivery, resultDocuments);
415405
}
416406

417407
private MapType invokeApplyTemplates() throws XPathException, SaxonApiException {
@@ -420,25 +410,12 @@ private MapType invokeApplyTemplates() throws XPathException, SaxonApiException
420410
final Item item = initialMatchSelection.itemAt(0);
421411
if (item instanceof Document) {
422412
final Source sourceIMS = new DOMSource((Document)item, context.getBaseURI().getStringValue());
423-
if (options.deliveryFormat == DeliveryFormat.RAW) {
424-
final Sequence existValue = Convert.ToExist.of(xslt30Transformer.applyTemplates(sourceIMS));
425-
return makeResultMap(options, existValue, resultDocuments);
426-
}
427413
xslt30Transformer.applyTemplates(sourceIMS, destination);
428414
} else {
429415
final XdmValue selection = toSaxon.of(initialMatchSelection);
430-
if (options.deliveryFormat == DeliveryFormat.RAW) {
431-
final Sequence existValue = Convert.ToExist.of(xslt30Transformer.applyTemplates(selection));
432-
return makeResultMap(options, existValue, resultDocuments);
433-
}
434416
xslt30Transformer.applyTemplates(selection, destination);
435417
}
436418
} else if (sourceNode.isPresent()) {
437-
if (options.deliveryFormat == DeliveryFormat.RAW) {
438-
xslt30Transformer.applyTemplates(sourceNode.get(), destination);
439-
final Sequence existValue = Convert.ToExist.of(delivery.getXdmValue());
440-
return makeResultMap(options, existValue, resultDocuments);
441-
}
442419
xslt30Transformer.applyTemplates(sourceNode.get(), destination);
443420
} else {
444421
throw new XPathException(FnTransform.this,
@@ -552,27 +529,6 @@ private MapType makeResultMap(final Options options, final Delivery delivery, fi
552529
return outputMap;
553530
}
554531

555-
private MapType makeResultMap(final Options options, final Sequence rawPrimaryOutput, final Map<URI, Delivery> resultDocuments) throws XPathException {
556-
557-
final MapType outputMap = new MapType(context);
558-
final AtomicValue outputKey;
559-
if (options.baseOutputURI.isPresent()) {
560-
outputKey = options.baseOutputURI.get();
561-
} else {
562-
outputKey = new StringValue("output");
563-
}
564-
565-
outputMap.add(outputKey, postProcess(outputKey, rawPrimaryOutput, options.postProcess));
566-
567-
for (final Map.Entry<URI, Delivery> resultDocument : resultDocuments.entrySet()) {
568-
final AnyURIValue key = new AnyURIValue(resultDocument.getKey());
569-
final Sequence value = postProcess(key, convertToDeliveryFormat(options, resultDocument.getValue()), options.postProcess);
570-
outputMap.add(key, value);
571-
}
572-
573-
return outputMap;
574-
}
575-
576532
private Sequence postProcess(final AtomicValue key, final Sequence before, final Optional<FunctionReference> postProcessingFunction) throws XPathException {
577533
if (postProcessingFunction.isPresent()) {
578534
FunctionReference functionReference = postProcessingFunction.get();

0 commit comments

Comments
 (0)