I have two strings.
The first one is a xml string, saved as a string, not from a file.
The second one is a string I load from a XSLT file with fs.readFile(...)
.
I already tried using libxslt
but can't install it via npm
due to some errors about MSBuildTools and so on.
Are there any alternatives for libxslt
? I already came across xslt-processor
too, but it only accepts files as parameters.
EDIT 1:
to provide you an overview, the XSLT file and an example XML file (both handled as strings in the app) can be downloaded here:
I somehow got a workaround for my problem:
xth
library (install via npm:npm i xth
)var xth = require('xth');
var xml = 'data:text/xml,' + encodeURIComponent(xmlString);
var xsl = './../components/ELGA_Stylesheet_v1-0.xsl';
Then, I just call the method xth as in the example at xth - npm
1 xth(xml, xsl, function (html) { 2 html = html.replace(/</g, "<"); 3 html = html.replace(/>/g, ">"); 4 html = html.replace(/&/g, "&"); 5 openWindow(html); 6 });
the item
html
is the xslt transformed string, I had one final problem: in the<script>
Tags of the output string, the symbols <,> and & were there as &lt;, &gt;, and &amp; which caused problems. lines 2 to 4 are the workaround for this issueopenWindow(html)
is my own method to open the result string in a new electron window.NOTE: one problem remains: as mentioned here, navigation via # in
<a href=#id>
doesn't work, because Chromium doesn't allow navigation to top frame to data uri.