Reputation: 847
Okay, I cannot make disable-output-escaping attribute to work. Here's my minimal example:
<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="2.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="xml" indent="yes"/>
<xsl:template match="/">
<
<xsl:text><</xsl:text>
<xsl:text disable-output-escaping="yes "><</xsl:text>
<xsl:variable name="break" select="'<'"/>
<xsl:copy-of select="$break"/>
<xsl:value-of select="$break" disable-output-escaping="yes"/>
<xsl:value-of select="$break" disable-output-escaping="no"/>
</xsl:template>
</xsl:stylesheet>
I am using the .Net processor in a C# application:
static void RunXslt(string xml)
{
XmlDocument xmlDocument = new XmlDocument();
xmlDocument.LoadXml(xml);
XslTransform myXslTransform = new XslTransform();
XmlTextWriter writer = new XmlTextWriter("C:\\output", null);
Stream xsltStream = Assembly.GetExecutingAssembly().GetManifestResourceStream("myProject.mytransform.xslt");
XmlReader xsltReader = XmlReader.Create(xsltStream);
myXslTransform.Load(xsltReader);
myXslTransform.Transform(xmlDocument, null, writer);
writer.Flush();
writer.Close();
}
All I get is < instead of <
What am I doing wrong here?
Upvotes: 0
Views: 251
Reputation: 403
I had the same problem a while a go, and as I receive all kind of different XML files (from great design to not that great) and as .NET does not support XSLT 2.0 out of the box, I decided to buy a library.
There are two to choose from: Altova XML and Saxon.
I don't think Microsoft has any plans on supporting XSLT2.0 in c#, so if you want to use XSLT 2.0 (or 3.0), you have to invest in one of the two libraries, or build your own - which I will not recommend.
Upvotes: 0
Reputation: 163458
I suspect that because you are using an XmlWriter as the destination, the serialization (and hence escaping) is being done by the XmlWriter, not by the transformation engine, and XmlWriter has no knowledge of disable-output-escaping. (This is why d-o-e is deprecated...)
I don't know the .net processor well enough, but there's probably some way of sending the output to a byte stream such that the transformation engine takes responsibility for serialization and escaping.
Upvotes: 2