Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/xpath/expr-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ export class ExprContext {
constructor(
nodeList: XNode[],
outputNodeList: XNode[],
xsltVersion: '1.0' | '2.0' | '3.0' = '1.0',
opt_position?: number,
opt_outputPosition?: number,
opt_outputDepth?: number,
Expand All @@ -102,6 +103,8 @@ export class ExprContext {
) {
this.nodeList = nodeList;
this.outputNodeList = outputNodeList;
this.xsltVersion = xsltVersion;

this.position = opt_position || 0;
this.outputPosition = opt_outputPosition || 0;

Expand Down Expand Up @@ -158,6 +161,7 @@ export class ExprContext {
return new ExprContext(
opt_nodeList || this.nodeList,
opt_outputNodeList || this.outputNodeList,
this.xsltVersion,
typeof opt_position !== 'undefined' ? opt_position : this.position,
typeof opt_outputPosition !== 'undefined' ? opt_outputPosition : this.outputPosition,
this.outputDepth,
Expand All @@ -176,6 +180,7 @@ export class ExprContext {
return new ExprContext(
this.nodeList,
opt_outputNodeList || this.outputNodeList,
this.xsltVersion,
this.position,
typeof opt_outputPosition !== 'undefined' ? opt_outputPosition : this.outputPosition,
typeof opt_outputDepth !== 'undefined' ? opt_outputDepth : this.outputDepth,
Expand Down
3 changes: 3 additions & 0 deletions src/xpath/expressions/function-call-expr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import {
formatNumber
} from '../functions';
import { extCardinal, extIf, extJoin } from '../functions/non-standard';
import { lowerCase, upperCase } from '../functions/standard-20';
import { BooleanValue } from '../values/boolean-value';
import { Expression } from './expression';

Expand All @@ -58,6 +59,7 @@ export class FunctionCallExpr extends Expression {
lang,
last,
'local-name': localName,
'lower-case': lowerCase,
matches,
name: _name,
'namespace-uri': namespaceUri,
Expand All @@ -76,6 +78,7 @@ export class FunctionCallExpr extends Expression {
'string-length': stringLength,
translate,
true: _true,
'upper-case': upperCase,

// TODO(mesch): The following functions are custom. There is a
// standard that defines how to add functions, which should be
Expand Down
15 changes: 15 additions & 0 deletions src/xpath/functions/standard-20.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ExprContext } from "../expr-context";
import { StringValue } from "../values";
import { assert } from "./internal-functions";

export function upperCase(context: ExprContext) {
assert(['2.0', '3.0'].includes(context.xsltVersion));
const str: string = this.args[0].evaluate(context).stringValue();
return new StringValue(str.toUpperCase());
}

export function lowerCase(context: ExprContext) {
assert(['2.0', '3.0'].includes(context.xsltVersion));
const str: string = this.args[0].evaluate(context).stringValue();
return new StringValue(str.toLowerCase());
}
2 changes: 1 addition & 1 deletion src/xpath/values/boolean-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class BooleanValue implements NodeValue {
this.type = 'boolean';
}

stringValue() {
stringValue(): string {
return `${this.value}`;
}

Expand Down
2 changes: 1 addition & 1 deletion src/xpath/values/node-set-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export class NodeSetValue implements NodeValue {
this.type = 'node-set';
}

stringValue() {
stringValue(): string {
if (this.value.length === 0) {
return '';
}
Expand Down
2 changes: 1 addition & 1 deletion src/xpath/values/number-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class NumberValue implements NodeValue {
this.type = 'number';
}

stringValue() {
stringValue(): string {
return `${this.value}`;
}

Expand Down
4 changes: 2 additions & 2 deletions src/xpath/values/string-value.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ export class StringValue implements NodeValue {
this.type = 'string';
}

stringValue() {
return this.value;
stringValue(): string {
return String(this.value);
}

booleanValue() {
Expand Down
Loading