I'm trying to generate some C# code using xslt - its working great until I get to generics and need to output some text like this:
MyClass<Type>
In this case I've found that the only way to emit this is to do the following:
MyClass<xsl:text disable-output-escaping="yes"><</xsl:text>Type<xsl:text disable-output-escaping="yes">></xsl:text>
Where:
<xsl:text />
, however usually the type Type
is given by some other template, e.g:<xsl:value-of select="@type" />
I don't mind having to write <
a lot, but I would like to avoid writing <xsl:text disable-output-escaping="yes"><</xsl:text>
for just a single character!
Is there any way of doing disable-output-escaping="yes"
for the entire document?
The reason why this wasn't working was all down to the I was applying the transform - I was using a XslCompiledTransform and an XmlWriter to transform my xml, however according to Microsoft XML Teams blog as soon as I use an XmlWriter to write my output the tag is ignored!
I fixed this by explicitly setting the XmlWriters output settings to those of the Xsl transform:
XmlWriterSettings ws = xslt.OutputSettings.Clone();
ws.CheckCharacters = false;
xslt.Transform("MyDocument.xml", XmlWriter.Create(Console.Out, ws));
Once I did this, the transform respected my tag, and all was well!
its working great until I get to generics and need to output some text like this:
MyClass<Type>
In this case I've found that the only way to emit this is to do the following:
MyClass<xsl:text disable-output-escaping="yes"><</xsl:text>Type<xsl:text
disable-output-escaping="yes">>
Certainly, this is not the only way and this is the worst way to produce such result.
Is there any way of doing disable-output-escaping="yes" for the entire document?
This is what the method="text"
attribute of <xsl:output>
is for. No need of DOE.
So, use the tex
t output method and then:
MyClass<Type>
Here is a complete small example.
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<xsl:template match="/">
MyClass<Type>
</xsl:template>
</xsl:stylesheet>
When the above transformation is applied on any XML document (not used), the wanted result is produced:
MyClass<Type>
I am the author of the XPath Visualizer, which produces IE-like presentation of XML files -- nowhere in thie code there is any DOE.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With