Generate xslt
When opening and saving documents, Xeditor requires xslt
transformations. These transformation files can mostly be pre-generated.
For this we use the xgen tool
again, which we have already added in the last chapter.
For additional information about why those transformations are required, please see our explanation on XML vs. HTML.
XSLT generation
Again, we can use scripts from the package.json
or run it directly. For the scripts we need the following entries in the package.json
:
// path/to/project/package.json
{
// ...
"scripts": {
// ...
"update:xslt": "xgen xslt ./src/js/config/types.gen.json --output ./WEB-INF/xsl"
},
// ...
}
Afterwards we can simply run this script via the command npm run update:xslt
and thus generate our xslt files.
We now have two new files ./WEB-INF/xsl/xml_to_html.xsl
and ./WEB-INF/xsl/html_to_xml.xsl
in our project.
Of course, you can also run the tool without adding it as a script:
./node_modules/.bin/xgen xslt ./src/js/config/types.gen.json --output ./WEB-INF/xsl
XSLT customization
To ensure that the XSLT files can be easily regenerated in the future when the schema is changed, we recommend using a new xslt file for the generation and simply including the generated file here.
For this we can create two new files ./WEB-INF/xsl/xml_to_html-override.xsl
and ./WEB-INF/xsl/html_to_xml-override.xsl
and insert the following template.
In our project these files with the correct content are already available.
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0"
xmlns:mml="http://www.w3.org/1998/Math/MathML"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xml="http://www.w3.org/XML/1998/namespace"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" omit-xml-declaration="yes" indent="no"/>
<!-- Include generated file -->
<!-- TODO: Add the file you want to override/customize -->
<!-- <xsl:include href="./xml_to_html.xsl"/> -->
<!-- <xsl:include href="./html_to_xml.xsl"/> -->
<!-- TODO: Add your customization -->
</xsl:stylesheet>