I want to transform a XML document, but having a problem.
My XSLT looks like this:
<?xml version="1.0" encoding="iso-8859-1" ?>
<xsl:stylesheet version="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="html" />
<xsl:strip-space elements="*" />
<xsl:template match="/">
<xsl:apply-templates select="address" />
</xsl:template>
<xsl:template match="address">
<xsl:value-of select="@street" />
<xsl:value-of select="@housenr" />
<xsl:value-of select="@zipcode" />
<xsl:value-of select="@city" />
<xsl:value-of select="@country" />
</xsl:template>
</xsl:stylesheet>
And the XML document I want to transform looks like this:
<address id="4" type="1"
typename="Postadres"
street="pak street"
housenr="420"
zipcode="42000"
city="Nill"
country="Lahore"
kix="" />
Here is the code I've written:
public static string Transform(XmlDocument doc, XmlDocument stylesheet)
{
var transform = new System.Xml.Xsl.XslCompiledTransform();
XmlDocument domOutput = new XmlDocument();
stylesheet.PreserveWhitespace = false;
transform.Load(stylesheet); // compiled stylesheet
MemoryStream oStream = new MemoryStream();
var writer = new System.IO.StringWriter();
transform.Transform(doc, (XsltArgumentList)null, oStream);
domOutput.Load(oStream);
return writer.ToString();
}
The following line throws an exception
transform.Transform(doc, (XsltArgumentList)null, oStream);
Exception message:
White space cannot be stripped from input documents that have already been loaded. Provide the input document as an XmlReader instead.
Can you tell me what I am doing wrong?
Thanks in advance!
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…