I've got a .NET library that uses an XSLT file for transforming beer xml files into json for a web app.
The XSLT file looks a lot like this:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text" omit-xml-declaration="yes" />
<xsl:template match="RECIPES">
{
{
"description": {
"name": "<xsl:value-of select="NAME"/>",
"style": "<xsl:value-of select="STYLE/NAME"/>",
...
And I'm converting using this piece of code in c#:
using(var writer = new StringWriter()){
_xsltCompiler.Transform(_document, null, writer);
json = writer.ToString();
}
Now, the problem is that curly braces and whitespace is missing from the output. And it used to work. From the source control history I can see no aparent changes lately. Any suggestions on how to fix this?
I would recommend transforming it initially to xml and storing it into a variable then applying a standard/general template to transform that to JSON. I would this this slightly different using XSLT 2.0 or 3.0 and implement
xml-to-json()
.This is my solution to the example above: