2

i have a problem like a lot of people with escaping the > sign. the data xml file looks like

<XML>
<check><![CDATA[value > 60]]></check>
</Xml>

with xslt i would like to create a c# function. the checks are items that gone be used in a if statement.

public void product(int value)
{
if( <xsl:value-of disable-output-escaping="yes" select="actie" />)

this should be: if( value > 60 ) but returns if( value &gt; 60 ) 

}

<xsl:value-of cdata-section-elements="check"/> can't be used becouse i can't use this data in a template.

disable-output-escaping just returns &gt;

hope one of u have a working solution.

thanking you in advance

Oded
  • 489,969
  • 99
  • 883
  • 1,009
thanksalot
  • 115
  • 2
  • 16
  • Good question, +1. See my answer for a complete and very easy solution. :) – Dimitre Novatchev Jan 17 '11 at 20:38
  • You wrote *I have a problem like a lot of people with escaping the > sign*. That's not a question, but a statement. Any XML consumer knows how to deal with character entities. Some people have problems when they try to use XML documents with no XML complain consumers. –  Jan 17 '11 at 20:40
  • Also, it's not clear the serialization method you need to use. There is no escape performed with `text` serialization method as point out by @Dimitre's answer. –  Jan 17 '11 at 20:42

2 Answers2

2

You don't need DOE at all. Just specify:

<xsl:output method="text"/>

and the result will be unescaped.

Here is a small example:

<xsl:stylesheet version="1.0"
 xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
 <xsl:output method="text"/>

    <xsl:template match="/*">
   public void product(int value)
       {
        if( <xsl:value-of select="check" />)
        }
  </xsl:template>
</xsl:stylesheet>

When this transformation is applied on any XML document (not used), the wanted, correct result is produced:

   public void product(int value)
        {
         if( value > 60)
        }

Remember:

  1. When the output method is "text", any characters that are escaped in the XML document, such as &, < (>, &quot; and &apos; usually do not need to be escaped at all) are produced unescaped in the output.

  2. Always try to avoid using DOE -- it is almost never required.

Dimitre Novatchev
  • 240,661
  • 26
  • 293
  • 431
0

Thanks vor the help but it wasn't the solution, had some help from a friend who told me i was doing it wrong on calling the xslt file What i dit was:

XPathDocument myXPathDoc = new XPathDocument("../../file.xml");
XslTransform myXslTrans = new XslTransform();
myXslTrans.Load("../../file.xslt");
XmlTextWriter myWriter = new XmlTextWriter("../../file.txt", null);
myXslTrans.Transform(myXPathDoc, null, myWriter);

i changed it to:

XslCompiledTransform myXslTrans = new XslCompiledTransform();
myXslTrans.Load("../../file.xslt");
myXslTrans.Transform("../../file.xml", "../../file.cs");

now it worked

thanksalot
  • 115
  • 2
  • 16
  • Using `XslCompiledTransform` class istead of old `XslTransform` class have nothing to do with your not so well defined question –  Jan 18 '11 at 18:20