@@ -291,13 +291,13 @@ export class Xslt {
291
291
this . xsltWithParam ( paramContext , template ) ;
292
292
293
293
for ( let i = 0 ; i < top . childNodes . length ; ++ i ) {
294
- let c = top . childNodes [ i ] ;
294
+ let childNode = top . childNodes [ i ] ;
295
295
if (
296
- c . nodeType == DOM_ELEMENT_NODE &&
297
- this . isXsltElement ( c , 'template' ) &&
298
- domGetAttributeValue ( c , 'name' ) == name
296
+ childNode . nodeType = == DOM_ELEMENT_NODE &&
297
+ this . isXsltElement ( childNode , 'template' ) &&
298
+ domGetAttributeValue ( childNode , 'name' ) == name
299
299
) {
300
- this . xsltChildNodes ( paramContext , c , output ) ;
300
+ this . xsltChildNodes ( paramContext , childNode , output ) ;
301
301
break ;
302
302
}
303
303
}
@@ -478,26 +478,26 @@ export class Xslt {
478
478
}
479
479
480
480
/**
481
- * Implements xsl:choose and its child nodes xsl:when and
482
- * xsl:otherwise.
483
- * @param input The Expression Context.
481
+ * Implements ` xsl:choose`, its child nodes ` xsl:when`, and
482
+ * ` xsl:otherwise` .
483
+ * @param context The Expression Context.
484
484
* @param template The template.
485
485
* @param output The output.
486
486
*/
487
- protected xsltChoose ( input : ExprContext , template : any , output : any ) {
487
+ protected xsltChoose ( context : ExprContext , template : XNode , output : any ) {
488
488
for ( const childNode of template . childNodes ) {
489
489
if ( childNode . nodeType !== DOM_ELEMENT_NODE ) {
490
490
continue ;
491
491
}
492
492
493
493
if ( this . isXsltElement ( childNode , 'when' ) ) {
494
494
const test = xmlGetAttribute ( childNode , 'test' ) ;
495
- if ( this . xPath . xPathEval ( test , input ) . booleanValue ( ) ) {
496
- this . xsltChildNodes ( input , childNode , output ) ;
495
+ if ( this . xPath . xPathEval ( test , context ) . booleanValue ( ) ) {
496
+ this . xsltChildNodes ( context , childNode , output ) ;
497
497
break ;
498
498
}
499
499
} else if ( this . isXsltElement ( childNode , 'otherwise' ) ) {
500
- this . xsltChildNodes ( input , childNode , output ) ;
500
+ this . xsltChildNodes ( context , childNode , output ) ;
501
501
break ;
502
502
}
503
503
}
@@ -662,25 +662,27 @@ export class Xslt {
662
662
* Evaluates a variable or parameter and set it in the current input
663
663
* context. Implements `xsl:variable`, `xsl:param`, and `xsl:with-param`.
664
664
*
665
- * @param input TODO
666
- * @param template TODO
665
+ * @param context The expression context.
666
+ * @param template The template node.
667
667
* @param override flag that defines if the value computed here
668
668
* overrides the one already in the input context if that is the
669
669
* case. I.e. decides if this is a default value or a local
670
670
* value. `xsl:variable` and `xsl:with-param` override; `xsl:param` doesn't.
671
671
*/
672
- protected xsltVariable ( input : ExprContext , template : any , override : boolean ) {
672
+ protected xsltVariable ( context : ExprContext , template : XNode , override : boolean ) {
673
673
const name = xmlGetAttribute ( template , 'name' ) ;
674
674
const select = xmlGetAttribute ( template , 'select' ) ;
675
675
676
676
let value : any ;
677
677
678
678
if ( template . childNodes . length > 0 ) {
679
679
const root = domCreateDocumentFragment ( template . ownerDocument ) ;
680
- this . xsltChildNodes ( input , template , root ) ;
680
+ this . xsltChildNodes ( context , template , root ) ;
681
681
value = new NodeSetValue ( [ root ] ) ;
682
682
} else if ( select ) {
683
- value = this . xPath . xPathEval ( select , input ) ;
683
+ value = this . xPath . xPathEval ( select , context ) ;
684
+ } else if ( name in context . variables ) {
685
+ value = context . variables [ name ] ;
684
686
} else {
685
687
let parameterValue = '' ;
686
688
const filteredParameter = this . options . parameters . filter ( ( p ) => p . name === name ) ;
@@ -690,8 +692,8 @@ export class Xslt {
690
692
value = new StringValue ( parameterValue ) ;
691
693
}
692
694
693
- if ( override || ! input . getVariable ( name ) ) {
694
- input . setVariable ( name , value ) ;
695
+ if ( override || ! context . getVariable ( name ) ) {
696
+ context . setVariable ( name , value ) ;
695
697
}
696
698
}
697
699
@@ -892,13 +894,13 @@ export class Xslt {
892
894
* current template node, in the current input context. This happens
893
895
* before the operation specified by the current template node is
894
896
* executed.
895
- * @param input TODO
896
- * @param template TODO
897
+ * @param context The Expression Context.
898
+ * @param template The template node.
897
899
*/
898
- protected xsltWithParam ( input : ExprContext , template : any ) {
899
- for ( const c of template . childNodes ) {
900
- if ( c . nodeType === DOM_ELEMENT_NODE && this . isXsltElement ( c , 'with-param' ) ) {
901
- this . xsltVariable ( input , c , true ) ;
900
+ protected xsltWithParam ( context : ExprContext , template : XNode ) {
901
+ for ( const childNode of template . childNodes ) {
902
+ if ( childNode . nodeType === DOM_ELEMENT_NODE && this . isXsltElement ( childNode , 'with-param' ) ) {
903
+ this . xsltVariable ( context , childNode , true ) ;
902
904
}
903
905
}
904
906
}
0 commit comments