Skip to content

Commit 28712ca

Browse files
upper-case and lower-case (XSLT 2.0) (#77)
* Base implementation. * Unit tests and adjustments.
1 parent effe57f commit 28712ca

File tree

8 files changed

+236
-190
lines changed

8 files changed

+236
-190
lines changed

src/xpath/expr-context.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ export class ExprContext {
8888
constructor(
8989
nodeList: XNode[],
9090
outputNodeList: XNode[],
91+
xsltVersion: '1.0' | '2.0' | '3.0' = '1.0',
9192
opt_position?: number,
9293
opt_outputPosition?: number,
9394
opt_outputDepth?: number,
@@ -102,6 +103,8 @@ export class ExprContext {
102103
) {
103104
this.nodeList = nodeList;
104105
this.outputNodeList = outputNodeList;
106+
this.xsltVersion = xsltVersion;
107+
105108
this.position = opt_position || 0;
106109
this.outputPosition = opt_outputPosition || 0;
107110

@@ -158,6 +161,7 @@ export class ExprContext {
158161
return new ExprContext(
159162
opt_nodeList || this.nodeList,
160163
opt_outputNodeList || this.outputNodeList,
164+
this.xsltVersion,
161165
typeof opt_position !== 'undefined' ? opt_position : this.position,
162166
typeof opt_outputPosition !== 'undefined' ? opt_outputPosition : this.outputPosition,
163167
this.outputDepth,
@@ -176,6 +180,7 @@ export class ExprContext {
176180
return new ExprContext(
177181
this.nodeList,
178182
opt_outputNodeList || this.outputNodeList,
183+
this.xsltVersion,
179184
this.position,
180185
typeof opt_outputPosition !== 'undefined' ? opt_outputPosition : this.outputPosition,
181186
typeof opt_outputDepth !== 'undefined' ? opt_outputDepth : this.outputDepth,

src/xpath/expressions/function-call-expr.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import {
3535
formatNumber
3636
} from '../functions';
3737
import { extCardinal, extIf, extJoin } from '../functions/non-standard';
38+
import { lowerCase, upperCase } from '../functions/standard-20';
3839
import { BooleanValue } from '../values/boolean-value';
3940
import { Expression } from './expression';
4041

@@ -58,6 +59,7 @@ export class FunctionCallExpr extends Expression {
5859
lang,
5960
last,
6061
'local-name': localName,
62+
'lower-case': lowerCase,
6163
matches,
6264
name: _name,
6365
'namespace-uri': namespaceUri,
@@ -76,6 +78,7 @@ export class FunctionCallExpr extends Expression {
7678
'string-length': stringLength,
7779
translate,
7880
true: _true,
81+
'upper-case': upperCase,
7982

8083
// TODO(mesch): The following functions are custom. There is a
8184
// standard that defines how to add functions, which should be

src/xpath/functions/standard-20.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { ExprContext } from "../expr-context";
2+
import { StringValue } from "../values";
3+
import { assert } from "./internal-functions";
4+
5+
export function upperCase(context: ExprContext) {
6+
assert(['2.0', '3.0'].includes(context.xsltVersion));
7+
const str: string = this.args[0].evaluate(context).stringValue();
8+
return new StringValue(str.toUpperCase());
9+
}
10+
11+
export function lowerCase(context: ExprContext) {
12+
assert(['2.0', '3.0'].includes(context.xsltVersion));
13+
const str: string = this.args[0].evaluate(context).stringValue();
14+
return new StringValue(str.toLowerCase());
15+
}

src/xpath/values/boolean-value.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class BooleanValue implements NodeValue {
99
this.type = 'boolean';
1010
}
1111

12-
stringValue() {
12+
stringValue(): string {
1313
return `${this.value}`;
1414
}
1515

src/xpath/values/node-set-value.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export class NodeSetValue implements NodeValue {
1010
this.type = 'node-set';
1111
}
1212

13-
stringValue() {
13+
stringValue(): string {
1414
if (this.value.length === 0) {
1515
return '';
1616
}

src/xpath/values/number-value.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export class NumberValue implements NodeValue {
99
this.type = 'number';
1010
}
1111

12-
stringValue() {
12+
stringValue(): string {
1313
return `${this.value}`;
1414
}
1515

src/xpath/values/string-value.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ export class StringValue implements NodeValue {
99
this.type = 'string';
1010
}
1111

12-
stringValue() {
13-
return this.value;
12+
stringValue(): string {
13+
return String(this.value);
1414
}
1515

1616
booleanValue() {

0 commit comments

Comments
 (0)