3333//
3434//
3535// Original author: Steffen Meschkat <mesch@google.com>
36- import he from 'he' ;
3736
3837import {
3938 XDocument ,
@@ -46,6 +45,7 @@ import {
4645 domCreateTextNode ,
4746 domGetAttribute ,
4847 domSetAttribute ,
48+ xmlGetAttribute ,
4949 xmlOwnerDocument ,
5050 xmlText ,
5151 xmlValue
@@ -99,7 +99,7 @@ export class Xslt {
9999 * @param output the root of the generated output, as DOM node.
100100 * @param _parameters Extra parameters.
101101 */
102- protected xsltProcessContext ( input : ExprContext , template : XNode , output : XNode , _parameters ?: any ) {
102+ protected xsltProcessContext ( input : ExprContext , template : XNode , output : XNode , _parameters ?: { [ key : string ] : any } ) {
103103 const outputDocument = xmlOwnerDocument ( output ) ;
104104
105105 if ( ! this . isXsltElement ( template ) ) {
@@ -125,7 +125,7 @@ export class Xslt {
125125 case 'apply-imports' :
126126 throw `not implemented: ${ template . localName } ` ;
127127 case 'apply-templates' :
128- select = this . xmlGetAttribute ( template , 'select' ) ;
128+ select = xmlGetAttribute ( template , 'select' ) ;
129129 if ( select ) {
130130 nodes = this . xPath . xPathEval ( select , input ) . nodeSetValue ( ) ;
131131 } else {
@@ -136,7 +136,7 @@ export class Xslt {
136136 this . xsltWithParam ( sortContext , template ) ;
137137 this . xsltSort ( sortContext , template ) ;
138138
139- mode = this . xmlGetAttribute ( template , 'mode' ) ;
139+ mode = xmlGetAttribute ( template , 'mode' ) ;
140140 top = template . ownerDocument . documentElement ;
141141
142142 templates = [ ] ;
@@ -165,7 +165,7 @@ export class Xslt {
165165 }
166166 break ;
167167 case 'attribute' :
168- nameexpr = this . xmlGetAttribute ( template , 'name' ) ;
168+ nameexpr = xmlGetAttribute ( template , 'name' ) ;
169169 name = this . xsltAttributeValue ( nameexpr , input ) ;
170170 node = domCreateDocumentFragment ( outputDocument ) ;
171171 this . xsltChildNodes ( input , template , node ) ;
@@ -175,7 +175,7 @@ export class Xslt {
175175 case 'attribute-set' :
176176 throw `not implemented: ${ template . localName } ` ;
177177 case 'call-template' :
178- name = this . xmlGetAttribute ( template , 'name' ) ;
178+ name = xmlGetAttribute ( template , 'name' ) ;
179179 top = template . ownerDocument . documentElement ;
180180
181181 paramContext = input . clone ( ) ;
@@ -210,7 +210,7 @@ export class Xslt {
210210 }
211211 break ;
212212 case 'copy-of' :
213- select = this . xmlGetAttribute ( template , 'select' ) ;
213+ select = xmlGetAttribute ( template , 'select' ) ;
214214 value = this . xPath . xPathEval ( select , input ) ;
215215 if ( value . type == 'node-set' ) {
216216 nodes = value . nodeSetValue ( ) ;
@@ -225,7 +225,7 @@ export class Xslt {
225225 case 'decimal-format' :
226226 throw `not implemented: ${ template . localName } ` ;
227227 case 'element' :
228- nameexpr = this . xmlGetAttribute ( template , 'name' ) ;
228+ nameexpr = xmlGetAttribute ( template , 'name' ) ;
229229 name = this . xsltAttributeValue ( nameexpr , input ) ;
230230 node = domCreateElement ( outputDocument , name ) ;
231231 domAppendChild ( output , node ) ;
@@ -237,7 +237,7 @@ export class Xslt {
237237 this . xsltForEach ( input , template , output ) ;
238238 break ;
239239 case 'if' :
240- test = this . xmlGetAttribute ( template , 'test' ) ;
240+ test = xmlGetAttribute ( template , 'test' ) ;
241241 if ( this . xPath . xPathEval ( test , input ) . booleanValue ( ) ) {
242242 this . xsltChildNodes ( input , template , output ) ;
243243 }
@@ -276,7 +276,7 @@ export class Xslt {
276276 this . xsltChildNodes ( input , template , output ) ;
277277 break ;
278278 case 'template' :
279- match = this . xmlGetAttribute ( template , 'match' ) ;
279+ match = xmlGetAttribute ( template , 'match' ) ;
280280 if ( match && this . xsltMatch ( match , input ) ) {
281281 this . xsltChildNodes ( input , template , output ) ;
282282 }
@@ -287,7 +287,7 @@ export class Xslt {
287287 output . appendChild ( node ) ;
288288 break ;
289289 case 'value-of' :
290- select = this . xmlGetAttribute ( template , 'select' ) ;
290+ select = xmlGetAttribute ( template , 'select' ) ;
291291 value = this . xPath . xPathEval ( select , input ) . stringValue ( ) ;
292292 node = domCreateTextNode ( outputDocument , value ) ;
293293 output . appendChild ( node ) ;
@@ -318,7 +318,7 @@ export class Xslt {
318318 */
319319 protected xsltWithParam ( input : any , template : any ) {
320320 for ( const c of template . childNodes ) {
321- if ( c . nodeType == DOM_ELEMENT_NODE && this . isXsltElement ( c , 'with-param' ) ) {
321+ if ( c . nodeType === DOM_ELEMENT_NODE && this . isXsltElement ( c , 'with-param' ) ) {
322322 this . xsltVariable ( input , c , true ) ;
323323 }
324324 }
@@ -338,10 +338,10 @@ export class Xslt {
338338
339339 for ( const c of template . childNodes ) {
340340 if ( c . nodeType == DOM_ELEMENT_NODE && this . isXsltElement ( c , 'sort' ) ) {
341- const select = this . xmlGetAttribute ( c , 'select' ) ;
341+ const select = xmlGetAttribute ( c , 'select' ) ;
342342 const expr = this . xPath . xPathParse ( select ) ;
343- const type = this . xmlGetAttribute ( c , 'data-type' ) || 'text' ;
344- const order = this . xmlGetAttribute ( c , 'order' ) || 'ascending' ;
343+ const type = xmlGetAttribute ( c , 'data-type' ) || 'text' ;
344+ const order = xmlGetAttribute ( c , 'order' ) || 'ascending' ;
345345 sort . push ( {
346346 expr,
347347 type,
@@ -361,9 +361,9 @@ export class Xslt {
361361 // case. I.e. decides if this is a default value or a local
362362 // value. xsl:variable and xsl:with-param override; xsl:param doesn't.
363363
364- protected xsltVariable ( input , template , override ) {
365- const name = this . xmlGetAttribute ( template , 'name' ) ;
366- const select = this . xmlGetAttribute ( template , 'select' ) ;
364+ protected xsltVariable ( input : any , template : any , override : any ) {
365+ const name = xmlGetAttribute ( template , 'name' ) ;
366+ const select = xmlGetAttribute ( template , 'select' ) ;
367367
368368 let value ;
369369
@@ -385,12 +385,14 @@ export class Xslt {
385385 // Implements xsl:chose and its child nodes xsl:when and
386386 // xsl:otherwise.
387387
388- protected xsltChoose ( input , template , output ) {
388+ protected xsltChoose ( input : any , template : any , output : any ) {
389389 for ( const childNode of template . childNodes ) {
390- if ( childNode . nodeType != DOM_ELEMENT_NODE ) {
390+ if ( childNode . nodeType !== DOM_ELEMENT_NODE ) {
391391 continue ;
392- } else if ( this . isXsltElement ( childNode , 'when' ) ) {
393- const test = this . xmlGetAttribute ( childNode , 'test' ) ;
392+ }
393+
394+ if ( this . isXsltElement ( childNode , 'when' ) ) {
395+ const test = xmlGetAttribute ( childNode , 'test' ) ;
394396 if ( this . xPath . xPathEval ( test , input ) . booleanValue ( ) ) {
395397 this . xsltChildNodes ( input , childNode , output ) ;
396398 break ;
@@ -408,8 +410,8 @@ export class Xslt {
408410 * @param template TODO
409411 * @param output TODO
410412 */
411- protected xsltForEach ( input , template , output ) {
412- const select = this . xmlGetAttribute ( template , 'select' ) ;
413+ protected xsltForEach ( input : any , template : any , output : any ) {
414+ const select = xmlGetAttribute ( template , 'select' ) ;
413415 const nodes = this . xPath . xPathEval ( select , input ) . nodeSetValue ( ) ;
414416 const sortContext = input . clone ( nodes [ 0 ] , 0 , nodes ) ;
415417 this . xsltSort ( sortContext , template ) ;
@@ -538,28 +540,6 @@ export class Xslt {
538540 return ret ;
539541 }
540542
541- /**
542- * Wrapper function to access attribute values of template element
543- // nodes. Currently this calls he.decode because in some DOM
544- // implementations the return value of node.getAttributeValue()
545- // contains unresolved XML entities, although the DOM spec requires
546- // that entity references are resolved by the DOM.
547- * @param node TODO
548- * @param name TODO
549- * @returns TODO
550- */
551- protected xmlGetAttribute ( node : XNode , name : string ) {
552- // TODO(mesch): This should not be necessary if the DOM is working
553- // correctly. The DOM is responsible for resolving entities, not the
554- // application.
555- const value = domGetAttribute ( node , name ) ;
556- if ( value ) {
557- return he . decode ( value ) ;
558- }
559-
560- return value ;
561- }
562-
563543 /**
564544 * Implements xsl:copy-of for node-set values of the select
565545 // expression. Recurses down the source node tree, which is part of
0 commit comments