@@ -125,7 +125,7 @@ export class Xslt {
125
125
}
126
126
}
127
127
128
- this . xsltProcessContext ( expressionContext , stylesheet ) ;
128
+ this . xsltProcessContext ( expressionContext , stylesheet , this . outputDocument ) ;
129
129
const transformedOutputXml = xmlTransformedText ( outputDocument , {
130
130
cData : false ,
131
131
escape : this . options . escape ,
@@ -209,7 +209,7 @@ export class Xslt {
209
209
if ( modifiedContext . nodeList [ j ] . nodeType === DOM_TEXT_NODE ) {
210
210
const textNodeContext = context . clone ( [ modifiedContext . nodeList [ j ] ] , undefined , 0 , undefined ) ;
211
211
// TODO: verify if it is okay to pass the own text node as template.
212
- this . commonLogicTextNode ( textNodeContext , modifiedContext . nodeList [ j ] ) ;
212
+ this . commonLogicTextNode ( textNodeContext , modifiedContext . nodeList [ j ] , output ) ;
213
213
} else {
214
214
const clonedContext = modifiedContext . clone (
215
215
[ modifiedContext . nodeList [ j ] ] ,
@@ -236,7 +236,8 @@ export class Xslt {
236
236
const documentFragment = domCreateDocumentFragment ( this . outputDocument ) ;
237
237
this . xsltChildNodes ( context , template , documentFragment ) ;
238
238
value = xmlValue2 ( documentFragment ) ;
239
- if ( output !== null && output !== undefined ) {
239
+
240
+ if ( output . nodeType === DOM_DOCUMENT_FRAGMENT_NODE ) {
240
241
domSetTransformedAttribute ( output , name , value ) ;
241
242
} else {
242
243
let sourceNode = context . nodeList [ context . position ] ;
@@ -270,6 +271,10 @@ export class Xslt {
270
271
parentSourceNode = newRootNode ;
271
272
}
272
273
274
+ // If the parent transformation is something like `xsl:element`, we should
275
+ // add a copy of the attribute to this element.
276
+ domSetTransformedAttribute ( output , name , value ) ;
277
+
273
278
// Some operations start by the tag attributes, and not by the tag itself.
274
279
// When this is the case, the output node is not set yet, so
275
280
// we add the transformed attributes into the original tag.
@@ -457,7 +462,8 @@ export class Xslt {
457
462
value = attribute . stringValue ( ) ;
458
463
node = domCreateTransformedTextNode ( this . outputDocument , value ) ;
459
464
node . siblingPosition = context . nodeList [ context . position ] . siblingPosition ;
460
- if ( output !== null && output !== undefined ) {
465
+
466
+ if ( output . nodeType === DOM_DOCUMENT_FRAGMENT_NODE ) {
461
467
output . appendTransformedChild ( node ) ;
462
468
} else {
463
469
context . outputNodeList [ context . outputPosition ] . appendTransformedChild ( node ) ;
@@ -720,18 +726,23 @@ export class Xslt {
720
726
* @param context The Expression Context.
721
727
* @param template The template, that contains the node value to be written.
722
728
*/
723
- private commonLogicTextNode ( context : ExprContext , template : XNode ) {
724
- const textNodeList = context . outputNodeList [ context . outputPosition ] . transformedChildNodes . filter (
725
- ( n ) => n . nodeType === DOM_TEXT_NODE
726
- ) ;
727
-
728
- if ( textNodeList . length > 0 ) {
729
- let node = textNodeList [ 0 ] ;
730
- node . transformedNodeValue = template . nodeValue ;
731
- } else {
729
+ private commonLogicTextNode ( context : ExprContext , template : XNode , output : XNode ) {
730
+ if ( output . nodeType === DOM_DOCUMENT_FRAGMENT_NODE ) {
732
731
let node = domCreateTransformedTextNode ( this . outputDocument , template . nodeValue ) ;
733
- node . transformedParentNode = context . outputNodeList [ context . outputPosition ] ;
734
- domAppendTransformedChild ( context . outputNodeList [ context . outputPosition ] , node ) ;
732
+ domAppendTransformedChild ( output , node ) ;
733
+ } else {
734
+ const textNodeList = context . outputNodeList [ context . outputPosition ] . transformedChildNodes . filter (
735
+ ( n ) => n . nodeType === DOM_TEXT_NODE
736
+ ) ;
737
+
738
+ if ( textNodeList . length > 0 ) {
739
+ let node = textNodeList [ 0 ] ;
740
+ node . transformedNodeValue = template . nodeValue ;
741
+ } else {
742
+ let node = domCreateTransformedTextNode ( this . outputDocument , template . nodeValue ) ;
743
+ node . transformedParentNode = context . outputNodeList [ context . outputPosition ] ;
744
+ domAppendTransformedChild ( context . outputNodeList [ context . outputPosition ] , node ) ;
745
+ }
735
746
}
736
747
}
737
748
@@ -747,7 +758,7 @@ export class Xslt {
747
758
protected xsltPassThrough ( context : ExprContext , template : XNode , output : XNode ) {
748
759
if ( template . nodeType == DOM_TEXT_NODE ) {
749
760
if ( this . xsltPassText ( template ) ) {
750
- this . commonLogicTextNode ( context , template ) ;
761
+ this . commonLogicTextNode ( context , template , output ) ;
751
762
}
752
763
} else if ( template . nodeType == DOM_ELEMENT_NODE ) {
753
764
let node : XNode ;
@@ -795,7 +806,7 @@ export class Xslt {
795
806
outputNode . transformedChildNodes . length - 1 ,
796
807
++ elementContext . outputDepth
797
808
) ;
798
- this . xsltChildNodes ( clonedContext , template ) ;
809
+ this . xsltChildNodes ( clonedContext , template , output ) ;
799
810
} else {
800
811
// This applies also to the DOCUMENT_NODE of the XSL stylesheet,
801
812
// so we don't have to treat it specially.
0 commit comments