I’m using XslCompiledTranform to transform XML/XSL.
This is my test XSL:
<span title="{./tooltip}" anattribute="{./tooltip}">
<xsl:value-of select="./tooltip"/>
</span>
You can see that for testing I put the same XSL value, namely @tooltip into the title attribute, an undefined anattribute attribute and also as text into the node.
In my XML the @tooltip is encoded like this “this is a <script> tag“. To be more precise: there are no HTML tags in the value. Everything is encoded, hence the < and >
If I transform the above I get as result:
<span title="this is a <script> tag" anattribute="this is a <script> tag">
this is a <script> tag
</span>
Why is keeping the encoding for node values and why is it substituting the encoded values for attributes? And most important: how can I stop XslCompiledTransform from behaving like that? I want my attributes exactly the way I specified them and no magic conversion going on.
My settings are as follows:
var oXSL = new XslCompiledTransform( );
XsltSettings oXslSettings = new XsltSettings( );
XmlUrlResolver oUriResolver = new XmlUrlResolver( );
oXslSettings.EnableDocumentFunction = true;
oXslSettings.EnableScript = false;
oXSL.Load( sXslPath, oXslSettings, oUriResolver );
René
For more information read spec: http://www.w3.org/TR/xslt#section-HTML-Output-Method
Use
<xsl:output method="xml"/>Input XML:
XSLT:
C# source code:
Output: