开发者

XSLT escaping >

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


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜