mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2025-10-16 12:05:41 +00:00
Important changes of the v0.18 version: - The previous libxmljs-tests.ts file used a require, thus made any variable from the imported 'libxmljs' typed 'any'. Hence, the test file actually tested no type declarations at all. This has been fixed via an ordinary 'import' statement. - Enabled strict null checks in tsconfig.json - Removed some exported classes (such as XMLDocument, HTMLDocument) which are neither used nor exported anymore in more recent libxmljs versions. - Added null return values to functions which sometimes return null, e.g. prevSibling(): Node|null.
100 lines
2.0 KiB
TypeScript
100 lines
2.0 KiB
TypeScript
import * as libxslt from 'libxslt';
|
|
import * as libxmljs from 'libxmljs';
|
|
|
|
const document: libxmljs.Document = libxslt.libxmljs.parseXmlString('<xml></xml>');
|
|
|
|
let stylesheet: libxslt.Stylesheet;
|
|
|
|
stylesheet = libxslt.parse('<xslt></xslt>');
|
|
|
|
stylesheet = libxslt.parse(document);
|
|
|
|
libxslt.parse('<xslt></xslt>', (err, result) => {
|
|
if (err == null) {
|
|
stylesheet = result;
|
|
}
|
|
});
|
|
|
|
libxslt.parse(document, (err, result) => {
|
|
if (err == null) {
|
|
stylesheet = result;
|
|
}
|
|
});
|
|
|
|
libxslt.parseFile('/path/to/file', (err, result) => {
|
|
if (err == null) {
|
|
stylesheet = result;
|
|
}
|
|
});
|
|
|
|
let applyOptions: libxslt.ApplyOptions = {};
|
|
|
|
applyOptions = {
|
|
outputFormat: 'string',
|
|
noWrapParams: true
|
|
};
|
|
|
|
let transformedString: string;
|
|
|
|
let transformedDocument: libxmljs.Document;
|
|
|
|
transformedString = stylesheet.apply('<xml></xml>');
|
|
|
|
transformedString = stylesheet.apply('<xml></xml>', {});
|
|
|
|
let applyResult = stylesheet.apply('<xml></xml>', {}, applyOptions);
|
|
|
|
if (typeof applyResult === 'string') {
|
|
transformedString = applyResult;
|
|
} else {
|
|
transformedDocument = applyResult;
|
|
}
|
|
|
|
stylesheet.apply('<xml></xml>', {}, applyOptions, (err, result) => {
|
|
if (err != null) {
|
|
return;
|
|
}
|
|
|
|
if (typeof result === 'string') {
|
|
transformedString = result;
|
|
} else {
|
|
transformedDocument = result;
|
|
}
|
|
});
|
|
|
|
transformedDocument = stylesheet.apply(document);
|
|
|
|
transformedDocument = stylesheet.apply(document, {});
|
|
|
|
applyResult = stylesheet.apply(document, {}, applyOptions);
|
|
|
|
if (typeof applyResult === 'string') {
|
|
transformedString = applyResult;
|
|
} else {
|
|
transformedDocument = applyResult;
|
|
}
|
|
|
|
stylesheet.apply(document, {}, applyOptions, (err, result) => {
|
|
if (err != null) {
|
|
return;
|
|
}
|
|
|
|
if (typeof result === 'string') {
|
|
transformedString = result;
|
|
} else {
|
|
transformedDocument = result;
|
|
}
|
|
});
|
|
|
|
stylesheet.applyToFile('/path/to/file', {}, applyOptions, (err, result) => {
|
|
if (err == null) {
|
|
transformedString = result;
|
|
}
|
|
});
|
|
|
|
stylesheet.applyToFile('/path/to/file', (err, result) => {
|
|
if (err == null) {
|
|
transformedString = result;
|
|
}
|
|
});
|