mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +03:00
Merge branch 'feat/xslt-tester' into chore/all-my-stuffs
# Conflicts: # components.d.ts # package.json # pnpm-lock.yaml # src/tools/index.ts
This commit is contained in:
commit
4222451a21
5 files changed
+158
No files matched your search
@@ -263,6 +263,7 @@
|
||||
"xml-js": "^1.6.11",
|
||||
"xpath-to-css": "^1.2.0",
|
||||
"xpath": "^0.0.34",
|
||||
"xslt-processor": "^3.0.1",
|
||||
"yaml": "^2.2.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
||||
Generated
+12
@@ -578,6 +578,9 @@ dependencies:
|
||||
xpath-to-css:
|
||||
specifier: ^1.2.0
|
||||
version: 1.2.0
|
||||
xslt-processor:
|
||||
specifier: ^3.0.1
|
||||
version: 3.2.2
|
||||
yaml:
|
||||
specifier: ^2.2.1
|
||||
version: 2.2.1
|
||||
@@ -15816,6 +15819,15 @@ packages:
|
||||
engines: {node: '>=0.6.0'}
|
||||
dev: false
|
||||
|
||||
/xslt-processor@3.2.2:
|
||||
resolution: {integrity: sha512-stgNu1l6goN5rH1mvd0R+WRCBOrypIF0qPB8wpW4ciFzExoaVlE1o/vuZ7N5yVtH6Rl917yRb773o59SaOgPTA==}
|
||||
dependencies:
|
||||
he: 1.2.0
|
||||
node-fetch: 2.7.0
|
||||
transitivePeerDependencies:
|
||||
- encoding
|
||||
dev: false
|
||||
|
||||
/xss@1.0.15:
|
||||
resolution: {integrity: sha512-FVdlVVC67WOIPvfOwhoMETV72f6GbW7aOabBC3WxN/oUdoEMDyLz4OgRv5/gck2ZeNqEQu+Tb0kloovXOfpYVg==}
|
||||
engines: {node: '>= 0.10.0'}
|
||||
|
||||
@@ -54,6 +54,7 @@ import { tool as websocketTester } from './websocket-tester';
|
||||
import { tool as weekNumberConverter } from './week-number-converter';
|
||||
import { tool as wpaPskGenerator } from './wpa-psk-generator';
|
||||
import { tool as xpathTester } from './xpath-tester';
|
||||
import { tool as xsltTester } from './xslt-tester';
|
||||
|
||||
import { tool as cssXpathConverter } from './css-xpath-converter';
|
||||
import { tool as cssSelectorsMemo } from './css-selectors-memo';
|
||||
@@ -339,6 +340,7 @@ export const toolsByCategory: ToolCategory[] = [
|
||||
dockerRunToDockerComposeConverter,
|
||||
dockerComposeToDockerRunConverter,
|
||||
xmlFormatter,
|
||||
xsltTester,
|
||||
yamlViewer,
|
||||
jsonEditor,
|
||||
emailNormalizer,
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
import { HandMove } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'XSLT tester',
|
||||
path: '/xslt-tester',
|
||||
description: 'Allows to test XML transformation using XSLT Stylesheets',
|
||||
keywords: ['xslt', 'xml', 'tester'],
|
||||
component: () => import('./xslt-tester.vue'),
|
||||
icon: HandMove,
|
||||
createdAt: new Date('2024-05-11'),
|
||||
});
|
||||
@@ -0,0 +1,131 @@
|
||||
<script setup lang="ts">
|
||||
import { XmlParser, Xslt } from 'xslt-processor';
|
||||
import { formatXml } from '../xml-formatter/xml-formatter.service';
|
||||
import { useValidation } from '@/composable/validation';
|
||||
|
||||
const xslt = ref(`<?xml version="1.0" encoding="UTF-8"?>
|
||||
<xsl:stylesheet version="1.0"
|
||||
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
||||
<xsl:template match="/">
|
||||
<html>
|
||||
<body>
|
||||
<h2>My CD Collection</h2>
|
||||
<table border="1">
|
||||
<tr bgcolor="#9acd32">
|
||||
<th>Title</th>
|
||||
<th>Artist</th>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>.</td>
|
||||
<td>.</td>
|
||||
</tr>
|
||||
</table>
|
||||
</body>
|
||||
</html>
|
||||
</xsl:template>
|
||||
</xsl:stylesheet>`);
|
||||
const xmlInput = ref(`<?xml version="1.0" encoding="UTF-8"?>
|
||||
<catalog>
|
||||
<cd>
|
||||
<title>Empire Burlesque</title>
|
||||
<artist>Bob Dylan</artist>
|
||||
<country>USA</country>
|
||||
<company>Columbia</company>
|
||||
<price>10.90</price>
|
||||
<year>1985</year>
|
||||
</cd>
|
||||
<cd>
|
||||
<title>Hide your heart</title>
|
||||
<artist>Bonnie Tyler</artist>
|
||||
<country>UK</country>
|
||||
<company>CBS Records</company>
|
||||
<price>9.90</price>
|
||||
<year>1988</year>
|
||||
</cd>
|
||||
</catalog>`);
|
||||
|
||||
const formatted = ref(false);
|
||||
const xmlOutput = computedAsync(async () => {
|
||||
const xmlString = xmlInput.value;
|
||||
const xsltString = xslt.value;
|
||||
const formatResult = formatted.value;
|
||||
|
||||
const xsltProcessor = new Xslt();
|
||||
const xmlParser = new XmlParser();
|
||||
|
||||
try {
|
||||
let xmlOutput = await xsltProcessor.xsltProcess(
|
||||
xmlParser.xmlParse(xmlString),
|
||||
xmlParser.xmlParse(xsltString),
|
||||
);
|
||||
if (formatResult) {
|
||||
xmlOutput = formatXml(xmlOutput);
|
||||
}
|
||||
return xmlOutput;
|
||||
}
|
||||
catch (e: any) {
|
||||
return e.toString();
|
||||
}
|
||||
});
|
||||
|
||||
const xsltValidation = useValidation({
|
||||
source: xslt,
|
||||
rules: [
|
||||
{
|
||||
validator: (v) => {
|
||||
const xmlParser = new XmlParser();
|
||||
xmlParser.xmlParse(v);
|
||||
return true;
|
||||
},
|
||||
message: 'Provided XSLT is not valid.',
|
||||
},
|
||||
],
|
||||
});
|
||||
const xmlInputValidation = useValidation({
|
||||
source: xmlInput,
|
||||
rules: [
|
||||
{
|
||||
validator: (v) => {
|
||||
const xmlParser = new XmlParser();
|
||||
xmlParser.xmlParse(v);
|
||||
return true;
|
||||
},
|
||||
message: 'Provided XML is not valid.',
|
||||
},
|
||||
],
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div style="max-width: 600px;">
|
||||
<c-card title="Input" mb-2>
|
||||
<c-input-text
|
||||
v-model:value="xslt"
|
||||
label="XLST"
|
||||
multiline
|
||||
placeholder="Put your XSLT here..."
|
||||
rows="5"
|
||||
:validation="xsltValidation"
|
||||
mb-2
|
||||
/>
|
||||
|
||||
<c-input-text
|
||||
v-model:value="xmlInput"
|
||||
label="XML"
|
||||
multiline
|
||||
placeholder="Put your XML here..."
|
||||
rows="5"
|
||||
:validation="xmlInputValidation"
|
||||
mb-2
|
||||
/>
|
||||
|
||||
<n-checkbox v-model:checked="formatted">
|
||||
Format XML Output?
|
||||
</n-checkbox>
|
||||
</c-card>
|
||||
|
||||
<c-card title="Output">
|
||||
<TextareaCopyable :value="xmlOutput" language="xml" />
|
||||
</c-card>
|
||||
</div>
|
||||
</template>
|
||||
Reference in new issue
Block a user