Skip to content

Commit f48ccf1

Browse files
authored
Merge pull request #10 from FrendsPlatform/preserve-whitespace
Preserve whitespace on transform
2 parents e7ea59a + 8fa09e6 commit f48ccf1

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

Frends.Xml.Tests/Tests.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,5 +272,22 @@ public void ConvertJsonToXmlString()
272272
var result = Frends.Xml.Xml.ConvertJsonToXml(new JsonToXmlInput() {Json = json});
273273
Assert.That(result, Does.Contain("<url>http://www.google.com</url>"));
274274
}
275+
276+
[Test]
277+
public void WhiteSpaceIsPreserved()
278+
{
279+
const string transformXml = @"<?xml version=""1.0""?>
280+
<test></test>";
281+
282+
const string xslt = @"<?xml version=""1.0""?>
283+
<xsl:stylesheet xmlns:xsl=""http://www.w3.org/1999/XSL/Transform"" version=""2.0"">
284+
<xsl:template match=""test"">
285+
<xsl:value-of select="".""/>
286+
</xsl:template>
287+
</xsl:stylesheet>";
288+
289+
var res = Frends.Xml.Xml.Transform(new TransformInput() { Xml = transformXml, Xslt = xslt });
290+
Assert.That(res, Is.EqualTo(@"<?xml version=""1.0"" encoding=""UTF-8""?>")); // no newline caused by empty tag
291+
}
275292
}
276293
}

Frends.Xml/Xml.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public static string Transform(TransformInput input)
6969
{
7070
//XmlDocument always produces MemoryStream where its encoding matches the input XML's declaration
7171
XmlDocument xmldoc = new XmlDocument();
72+
xmldoc.PreserveWhitespace = true;
7273
xmldoc.LoadXml(input.Xml);
7374
xmldoc.Save(inputStream);
7475
xmldoc = null;

0 commit comments

Comments
 (0)