XSLT escaping >

三世轮回 提交于 2019-12-24 02:54:06

问题


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


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/4716998/xslt-escaping-gt

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!