@@ -41,6 +41,7 @@ import {
4141} from './constants' ;
4242import { Expression } from './xpath/expressions/expression' ;
4343import { StringValue , NodeSetValue } from './xpath/values' ;
44+ import { LocationExpr } from './xpath/expressions' ;
4445
4546/**
4647 * The main class for XSL-T processing. The implementation is NOT
@@ -68,9 +69,13 @@ import { StringValue, NodeSetValue } from './xpath/values';
6869 */
6970export class Xslt {
7071 xPath : XPath ;
72+ outputMethod : string ;
73+ outputOmitXmlDeclaration : string ;
7174
7275 constructor ( ) {
7376 this . xPath = new XPath ( ) ;
77+ this . outputMethod = "xml" ;
78+ this . outputOmitXmlDeclaration = "no" ;
7479 }
7580
7681 /**
@@ -273,10 +278,8 @@ export class Xslt {
273278 case 'otherwise' :
274279 throw `error if here: ${ template . localName } ` ;
275280 case 'output' :
276- // Ignored. -- Since we operate on the DOM, and all further use
277- // of the output of the XSL transformation is determined by the
278- // browser that we run in, this parameter is not applicable to
279- // this implementation.
281+ this . outputMethod = xmlGetAttribute ( template , 'method' ) ;
282+ this . outputOmitXmlDeclaration = xmlGetAttribute ( template , 'omit-xml-declaration' ) ;
280283 break ;
281284 case 'preserve-space' :
282285 throw `not implemented: ${ template . localName } ` ;
@@ -656,32 +659,41 @@ export class Xslt {
656659 protected xsltMatch ( match : string , context : ExprContext ) {
657660 const expr = this . xPath . xPathParse ( match ) ;
658661
659- if ( expr . steps . length <= 0 ) {
662+ if ( expr instanceof LocationExpr ) {
663+ return this . xsltLocationExpressionMatch ( match , expr , context ) ;
664+ }
665+
666+ // TODO: Other expressions
667+ return true ;
668+ }
669+
670+ private xsltLocationExpressionMatch ( match : string , expression : LocationExpr , context : ExprContext ) {
671+ if ( expression === undefined || expression . steps === undefined || expression . steps . length <= 0 ) {
660672 throw new Error ( 'Error resolving XSLT match: Location Expression should have steps.' ) ;
661673 }
662674
663- const firstStep = expr . steps [ 0 ] ;
675+ const firstStep = expression . steps [ 0 ] ;
664676
665677 // Shortcut for the most common case.
666678 if (
667- expr . steps &&
668- ! expr . absolute &&
669- expr . steps . length == 1 &&
679+ expression . steps &&
680+ ! expression . absolute &&
681+ expression . steps . length == 1 &&
670682 firstStep . axis == 'child' &&
671683 firstStep . predicate . length === 0
672684 ) {
673685 return firstStep . nodetest . evaluate ( context ) . booleanValue ( ) ;
674686 }
675687
676- if ( expr . absolute && firstStep . axis !== 'self' ) {
688+ if ( expression . absolute && firstStep . axis !== 'self' ) {
677689 // TODO: `xPathCollectDescendants()`?
678690 const levels = match . split ( '/' ) ;
679691 if ( levels . length > 1 ) {
680- return this . absoluteXsltMatch ( levels , expr , context ) ;
692+ return this . absoluteXsltMatch ( levels , expression , context ) ;
681693 }
682694 }
683695
684- return this . relativeXsltMatch ( expr , context ) ;
696+ return this . relativeXsltMatch ( expression , context ) ;
685697 }
686698
687699 /**
0 commit comments