25
25
import com .evolvedbinary .j8fu .tuple .Tuple2 ;
26
26
import com .github .benmanes .caffeine .cache .Cache ;
27
27
import com .github .benmanes .caffeine .cache .Caffeine ;
28
+ import com .github .krukow .clj_lang .PersistentTreeMap ;
28
29
import io .lacuna .bifurcan .IEntry ;
29
30
import net .jpountz .xxhash .XXHash64 ;
30
31
import net .jpountz .xxhash .XXHashFactory ;
@@ -516,12 +517,13 @@ private MapType makeResultMap(final Options options, final Delivery delivery, fi
516
517
outputKey = new StringValue ("output" );
517
518
}
518
519
519
- final Sequence primaryValue = convertToDeliveryFormat (options , delivery );
520
+ final Sequence primaryValue = postProcess ( outputKey , convertToDeliveryFormat (options , delivery ), options . postProcess );
520
521
outputMap .add (outputKey , primaryValue );
521
522
522
523
for (final Map .Entry <URI , Delivery > resultDocument : resultDocuments .entrySet ()) {
523
- final Sequence value = convertToDeliveryFormat (options , resultDocument .getValue ());
524
- outputMap .add (new AnyURIValue (resultDocument .getKey ()), value );
524
+ final AnyURIValue key = new AnyURIValue (resultDocument .getKey ());
525
+ final Sequence value = postProcess (key , convertToDeliveryFormat (options , resultDocument .getValue ()), options .postProcess );
526
+ outputMap .add (key , value );
525
527
}
526
528
527
529
return outputMap ;
@@ -537,16 +539,26 @@ private MapType makeResultMap(final Options options, final Sequence rawPrimaryOu
537
539
outputKey = new StringValue ("output" );
538
540
}
539
541
540
- outputMap .add (outputKey , rawPrimaryOutput );
542
+ outputMap .add (outputKey , postProcess ( outputKey , rawPrimaryOutput , options . postProcess ) );
541
543
542
544
for (final Map .Entry <URI , Delivery > resultDocument : resultDocuments .entrySet ()) {
543
- final Sequence value = convertToDeliveryFormat (options , resultDocument .getValue ());
544
- outputMap .add (new AnyURIValue (resultDocument .getKey ()), value );
545
+ final AnyURIValue key = new AnyURIValue (resultDocument .getKey ());
546
+ final Sequence value = postProcess (key , convertToDeliveryFormat (options , resultDocument .getValue ()), options .postProcess );
547
+ outputMap .add (key , value );
545
548
}
546
549
547
550
return outputMap ;
548
551
}
549
552
553
+ private Sequence postProcess (final AtomicValue key , final Sequence before , final Optional <FunctionReference > postProcessingFunction ) throws XPathException {
554
+ if (postProcessingFunction .isPresent ()) {
555
+ FunctionReference functionReference = postProcessingFunction .get ();
556
+ return functionReference .evalFunction (null , null , new Sequence []{key , before });
557
+ } else {
558
+ return before ;
559
+ }
560
+ }
561
+
550
562
private Sequence convertToDeliveryFormat (final Options options , final Delivery delivery ) throws XPathException {
551
563
552
564
switch (options .deliveryFormat ) {
@@ -1041,6 +1053,8 @@ private Map<net.sf.saxon.s9api.QName, XdmValue> readParamsMap(final Optional<Map
1041
1053
final Optional <Long > sourceTextChecksum ;
1042
1054
final String stylesheetNodeDocumentPath ;
1043
1055
1056
+ final Optional <FunctionReference > postProcess ;
1057
+
1044
1058
Options (final MapType options ) throws XPathException {
1045
1059
xsltSource = getStylesheet (options );
1046
1060
@@ -1107,6 +1121,8 @@ private Map<net.sf.saxon.s9api.QName, XdmValue> readParamsMap(final Optional<Map
1107
1121
serializationParams = FnTransform .SERIALIZATION_PARAMS .get (xsltVersion , options );
1108
1122
1109
1123
validateRequestedProperties (FnTransform .REQUESTED_PROPERTIES .get (xsltVersion , options ).orElse (new MapType (context )));
1124
+
1125
+ postProcess = FnTransform .POST_PROCESS .get (xsltVersion , options );
1110
1126
}
1111
1127
1112
1128
private DeliveryFormat getDeliveryFormat (final float xsltVersion , final MapType options ) throws XPathException {
0 commit comments